6

ActionMailerアプリケーションで「お問い合わせ」フォームのメールを送信するために使用しています。
メールの送信に Mandrill アプリを使用しています。設定は次のとおりです。

config/environments/development.rb

  config.action_mailer.perform_deliveries = true 
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :address              => "smtp.mandrillapp.com",
    :port                 => 587,
    :enable_starttls_auto => true,
    :user_name            => 'SMTP username i.e Mandrill a/c username',
    :password             => 'API key for development',
    :domain               => 'example.com',
    :authentication       => 'plain'
  }

config/environments/production.rb

行を削除
config.action_mailer.raise_delivery_errors = true
し、 本番用のパスワードを変更しました。これは、本番用の Mandrill アプリ API キーです。

app/mailers/contactus_mailer.rb

class ContactusMailer < ActionMailer::Base

  default :from => "noreply@example.com"
  default :to => "help@example.com"

  def new_message(message)
    @message = message
    mail(:subject => "[WebsiteName] #{message.name + " - " + message.email}")
  end

end

カスタム ドメインでの上記のアカウントの有効性 - example.com

上記の電子メール アカウント (つまりnoreply@example.com& help@example.com) はプロビジョニングされており、完全に機能しています。上記のアカウントは Outlook.com でセットアップされており、ドメインexample.comの MX レコードも再確認しました。ドメイン設定はドメインに対してアクティブです。証拠として、アカウントから両方のアカウントでメールを送受信できます。

開発環境と本番環境のログ:

両方の環境でお問い合わせフォームを使用すると、ActionMailer はエラーを報告せず、ホームページに正常にリダイレクトされます。

Started POST "/contact" for 127.0.0.1 at 2013-08-18 12:35:37 +0530
Processing by MessagesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"UNgMrA04yk4sIbqtXjlLvLvDINgrBT5eP0wMSRYNgPs=", "message"=>{"name"=>"Dummy name", "email"=>"abc@pqr.com", "content"=>"Random body"}, "commit"=>"Send Message"}
  Rendered contactus_mailer/new_message.text.erb (0.5ms)

Sent mail to help@example.com (2679ms)
Date: Sun, 18 Aug 2013 12:35:38 +0530
From: noreply@example.com
To: help@example.com
Message-ID: <52107242dbf6c_12a7f3fd8b1835ad03979@Jatins-MacBook-Pro.local.mail>
Subject: [WebsiteName] Dummy name - abc@pqr.com
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

Name: Dummy name    
Email: abc@pqr.com
Body: Random body

Redirected to http://localhost:3000/
Completed 302 Found in 3841ms (ActiveRecord: 0.0ms)

本番環境の Mandrill アプリ API ログ:

完全なリクエスト:

{
    "from_email": null,
    "from_name": null,
    "async": false,
    "key": "API key for production",
    "raw_message": "Received: from example.com (unknown [23.20.245.109])\n\t(Authenticated sender: key_production@gmail.com)\n\tby ip-10-31-147-25 (Postfix) with ESMTPSA id 6811A151A064\n\tfor <help@example.com>; Sun, 18 Aug 2013 08:19:11 +0000 (UTC)\nDate: Sun, 18 Aug 2013 08:19:11 +0000\nFrom: noreply@example.com\nTo: help@example.com\nMessage-ID: <5210837f5ce24_26e56b87992f@5c11fd99-5533-4855-af78-40e02c939412.mail>\nSubject: [WebsiteName] Dummy name - abc@pqr.com\nMime-Version: 1.0\nContent-Type: text/plain;\n charset=UTF-8\nContent-Transfer-Encoding: 7bit\n\nName: Dummy name\n\nEmail: abc@pqr.com\n\nBody: Random body",
    "to": [
        "help@example.com"
    ]
}

完全な応答:

[
    {
        "email": "help@example.com",
        "status": "rejected",
        "_id": "9c9f88c588ee4f369437b8dd5d531c8c",
        "reject_reason": "soft-bounce"
    }
]

開発環境の Mandrill アプリ API ログ:

開発環境の完全なリクエスト。本番環境に似ています。ただし、開発中の反応は異なります。
完全な応答:

[
    {
        "email": "help@example.com",
        "status": "sent",
        "_id": "e67f31f893a84ecdb0ed2438e5741ce1",
        "reject_reason": null
    }
]

注:help@example.com開発環境と本番環境の両方で、自分のアカウントに電子メールが届きません。
クエリ:

  1. 本番環境では拒否ステータスとソフト バウンス拒否理由が表示されるのに、開発環境では送信済みステータスと拒否理由が表示されないのはなぜですか。

  2. どちらの場合もメールが届かないのはなぜですか?

PS
最初は、資格情報とともにSMTPサーバーとしてMandrill app使用していませんでしたが、うまくいきませんでした。その後、Google で調べた後、Mandrill に切り替えました。 誰かが Outlook メールのセットアップを手伝ってくれれば、それも同様に良いことです。そうすれば、Mandrill はまったく必要なくなります。smtp.live.comno reply@example.com

4

2 に答える 2

4

Mandrill の有無にかかわらず動作するようになりました。7 日後までメールが届きませんでした。受信トレイはすべてのテスト メールであふれていました。

DNS、メール アカウントの TXT レコードに問題があったようで、遅延が発生していました。

また、Mandrill なしで試してみましたが、メールは適切に送信されています。そこで、 Outlookの設定をここに投稿します。他の誰かにとって便利になるかもしれません。

  config.action_mailer.perform_deliveries = true 
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
   :address              => "smtp.live.com",
   :port                 => 587,
   :enable_starttls_auto => true,
   :user_name            => 'noreply@example.com',
   :password             => 'password',
   :domain               => 'example.com',
   :authentication       => 'plain'
 }

注: 本番環境で使用する場合は、falseraise_delivery_errorsに設定してください。

于 2013-09-02T09:17:45.667 に答える