我正在使用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 App API日志:
与生产环境相似,开发环境下的完整请求也类似。但是,在开发环境中响应会有所不同。
完整响应:
[
{
"email": "help@example.com",
"status": "sent",
"_id": "e67f31f893a84ecdb0ed2438e5741ce1",
"reject_reason": null
}
]
注意: 我的账户 help@example.com
在开发和生产环境中都无法接收邮件。
问题:
为什么在生产环境中我的邮件被拒绝并显示软弹回原因,而在开发环境中则显示发送状态且没有拒绝原因。
为什么两种情况下我都无法接收任何邮件?
P.S.
最初我使用的是 smtp.live.com
作为 SMTP 服务器以及 no reply@example.com
的凭据,但并未成功。
之后经过一番谷歌搜索后我转向了 Mandrill。
如果有人能帮忙设置 Outlook 邮箱将会很好,这样就不需要使用 Mandrill 了。
authentication: :login
以使消息传递。 - simonlehmann