ActionMailer响应“501 5.5.4无效参数”

时间:2013-09-02 19:08:23

标签: ruby-on-rails ruby devise ruby-on-rails-4 mailgun

我正在使用Ruby 2.0.0上的Rails 4开发应用程序。该应用程序在Devise注册后发送电子邮件。

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

应用程序/模型/ sponsor.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.tldno-reply@domain.tld

1 个答案:

答案 0 :(得分:2)

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