使用ActionMailer和Outlook/Mandrillapp SMTP服务器发送邮件

Jat*_*tra 6 smtp ruby-on-rails actionmailer outlook.com mandrill

我正在使用ActionMailer我的申请表中的"联系我们"表单发送邮件.
我正在使用Mandrill应用程序发送我的电子邮件.这些是我的设置:

配置/环境/ 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'
  }
Run Code Online (Sandbox Code Playgroud)

配置/环境/ production.rb

我已删除该行
config.action_mailer.raise_delivery_errors = true
并更改了生产密码 - 这是用于生产的Mandrill app API密钥.

应用程序/邮寄者/ 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
Run Code Online (Sandbox Code Playgroud)

以上帐户对自定义域的有效性 - 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)
Run Code Online (Sandbox Code Playgroud)

适用于生产环境的Mandrill App 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"
    ]
}
Run Code Online (Sandbox Code Playgroud)

完整回复:

[
    {
        "email": "help@example.com",
        "status": "rejected",
        "_id": "9c9f88c588ee4f369437b8dd5d531c8c",
        "reject_reason": "soft-bounce"
    }
]
Run Code Online (Sandbox Code Playgroud)

用于开发环境的Mandrill App API日志:

完整的发展要求环境 类似于生产环境.但是,在开发过程中,响应是不同的.
完整回复:

[
    {
        "email": "help@example.com",
        "status": "sent",
        "_id": "e67f31f893a84ecdb0ed2438e5741ce1",
        "reject_reason": null
    }
]
Run Code Online (Sandbox Code Playgroud)

注意:help@example.com在开发和生产环境中都没有收到我帐户的电子邮件.
查询:

  1. 为什么我被拒绝状态和软反弹拒绝生产环境的原因,而对于开发它说发送状态而没有拒绝原因.

  2. 为什么我在这两种情况下都没有收到任何邮件?

PS
最初,我没有使用Mandrill app并且正在使用smtp.live.com我的SMTP服务器以及我的no reply@example.com凭据,但这没有用.然后我在谷歌挖掘之后切换到了Mandrill.
如果有人可以帮助Outlook邮件设置,那也同样好.这样,Mandrill根本不需要.

Jat*_*tra 4

不管有没有山魈,我都能正常工作。直到 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'
 }
Run Code Online (Sandbox Code Playgroud)

注意:要在生产中使用,请设置raise_delivery_errorsfalse