Joh*_*ath 12 amazon smtp ruby-on-rails amazon-web-services
我有一个Rails应用程序配置为通过SMTP使用Amazon SES.但是,当我尝试发送电子邮件时,它似乎在一分钟后超时,我得到了一个EOFError.它闻起来像一个配置问题 - 电子邮件似乎构造得很好,我可以从AWS SES控制台发送自己的测试电子邮件.这是沙盒模式,应用程序正在开发模式下运行,但发送和接收电子邮件都已通过SES验证,并且development.rb设置为:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
Run Code Online (Sandbox Code Playgroud)
我尝试了一百万个配置变化; 这开始让我开车香蕉.非常非常感谢任何帮助或指导.更多细节:
smtp配置,我在初始化程序中:
ActionMailer::Base.smtp_settings = {
:address => "email-smtp.us-east-1.amazonaws.com",
:port => "465",
:authentication => :plain,
:enable_starttls_auto => true,
:user_name => "1234",
:password => "abcde"
}
Run Code Online (Sandbox Code Playgroud)
带有错误的日志,为简洁起见有点截断:
Sent mail to john@phu.com (59929ms)
Date: Tue, 20 Dec 2011 03:08:37 -0800
From: contact@phu.com
To: john@phu.com
Message-ID: <4ef06cb5ed3c_d73c3fc604c34d4491943@Johns-MacBook-Pro.local.mail>
Subject: Your invitation to Phu
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
....
Completed 500 Internal Server Error in 60564ms
EOFError (end of file reached):
app/controllers/admin_controller.rb:61:in `block in send_invite'
app/controllers/admin_controller.rb:46:in `send_invite'
Run Code Online (Sandbox Code Playgroud)
小智 10
还有一个没有来自Mihir的猴子补丁解决方案的解决方案(根据AWS SES文档,http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/SMTP.Connecting.html,是TLS包装解决方案) ,通过使用端口587和:enable_starttls_auto选项(STARTTLS解决方案).所以修改后的配置是这样的:
config.action_mailer.default_url_options = { host: “<example.com>” }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address: “email-smtp.us-east-1.amazonaws.com”,
:port: 587,
:domain: “<example.com>”,
:authentication: :login,
:user_name: “<your aws smtp username>”,
:password: “<your aws smtp password>”,
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
小智 6
如果您想使用SMTP(而不是AWS-SES gem),这是一个解决方案
http://blog.readypulse.com/2012/01/06/amazon-ses-smtp-emails-using-rails-3-1-in-three-easy-steps/
注意事项
AWS SMTP仅适用于TLS AWS SMTP不支持STARTTLS ActionMailer的配置没有简单的TLS切换.要遵循的步骤
在AWS控制台上启用SMTP支持 - 请参阅此处的说明.在config/initializers目录下创建初始化程序.我称之为amazon_ses.rb并将以下代码添加到Money补丁ActionMailer的SMTP设置中.
module Net
class SMTP
def tls?
true
end
end
end
Run Code Online (Sandbox Code Playgroud)
在development.rb和production.rb文件中添加以下代码.修改设置以匹配您的环境.
config.action_mailer.default_url_options = { host: “<example.com>” }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: “email-smtp.us-east-1.amazonaws.com”,
port: 465,
domain: “<example.com>”,
authentication: :login,
user_name: “<your aws smtp username>”,
password: “<your aws smtp password>”
}
Run Code Online (Sandbox Code Playgroud)
在发送 EHLO 命令之前,SES 需要 SSL 会话。
我知道 System.Net.Mail 不适用于 SES,因为 System.Net.Mail 在 SMTP 会话启动后启动 TLS。
| 归档时间: |
|
| 查看次数: |
4641 次 |
| 最近记录: |