3

我正在使用 Rails 4 在 Ruby 2.0.0 上开发应用程序。在 Devise 中注册后,应用程序会发送一封电子邮件。

这是发送电子邮件的代码:

应用程序/模型/赞助商.rb:

after_create :send_email_to_admin

private

def send_email_to_admin
    AdminMailer.new_sponsor_email(self).deliver
end

应用程序/邮件程序/admin_mailer.rb

class AdminMailer < ActionMailer::Base
  default to: '**removed**'

  def new_sponsor_email(sponsor)
    @sponsor = sponsor
    p @sponsor
    mail(subject: "New Sponsor Registration")
  end
end

这是从日志文件生成的电子邮件:

Sent mail to **removed** (725.5ms)
Date: Mon, 02 Sep 2013 15:01:03 -0400
From: **removed**
To: **removed**
Message-ID: <5224e06f4dddd_2e5a3fa0452dcfd874597@centaur.mail>
Subject: New Sponsor Registration
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

A new sponsor has signed up!
==========================

----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
  </head>
  <body>
    <h1>A new sponsor has signed up!</h1>
  </body>
</html>

----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a--

当我尝试通过创建赞助商来测试代码时,我得到了这个错误:

Net::SMTPSyntaxError in Devise::RegistrationsController#create
501 5.5.4 Invalid argument

我的理解是,这通常是因为电子邮件是无效电子邮件,但我所有的电子邮件都非常简单,格式为name@domain.tldand no-reply@domain.tld

4

1 回答 1

3

问题似乎是我在 smtp_settings 中使用了“域”。当我删除它时,我能够从 Mailgun 和 Gmail 发送电子邮件

于 2013-09-02T19:19:22.207 回答