3

Ruby 2.0.0 で Rails 4 を使用するアプリケーションに取り組んでいます。アプリケーションは、Devise での登録後にメールを送信します。

これは、電子メールを送信するコードです。

アプリ/モデル/スポンサー.rb:

after_create :send_email_to_admin

private

def send_email_to_admin
    AdminMailer.new_sponsor_email(self).deliver
end

app/mailers/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.tldですno-reply@domain.tld

4

1 に答える 1

3

問題は、smtp_settings で「ドメイン」を使用していたことにあるようです。それを削除すると、Mailgun と Gmail の両方からメールを送信できるようになりました

于 2013-09-02T19:19:22.207 に答える