我正在尝试将我们的Rails应用转换为使用亚马逊的SES服务进行电子邮件发送。该应用程序使用Ruby 1.8.6和Rails 2.2.2。
SES要求电子邮件使用TLS(ssl样式加密),这在Ruby 1.8.6中是不受支持的,但是我找到了一个补丁来修补它,在这里:https://github.com/seattlerb/smtp_tls
我正在测试从我的控制台发送电子邮件,如下所示:
options = {
:address => "email-smtp.eu-west-1.amazonaws.com",
:port => 587,
:user_name => "my-ses-smtp-username",
:password => "my-ses-smtp-password",
:authentication => :login
}
smtp = Net::SMTP.new options[:address], options[:port]
smtp.enable_starttls
smtp.start Socket.gethostname, options[:user_name], options[:password], options[:authentication] do |server|
server.send_message "subject: hello\nblah blah\n\n", "verified_email1@ourdomain.com", "verified_email2@ourdomain.com"
end
“verified_email1@ourdomain.com”和“verified_email2@ourdomain.com”都已在SES上验证,“ourdomain.com”是我们在那里注册的域名。
我在SES上使用Sandbox模式,并使用他们自己的电子邮件测试控制台向已验证的地址发送了一些电子邮件,这些电子邮件已经确定。
SES上的统计信息页面列出了一封已发送的电子邮件,尽管下面的时间线图表实际上表示已经有6次发送和一次反弹。无论哪种方式,我都希望看到一些事情发生,但一无所获。
我已经对Net :: SMTP进行了一些登录,以查看上述请求发生了什么,从我有限的知识看它确实看起来不错:
net/smtp.rb:672:in `check_response': res = "220 email-smtp.amazonaws.com ESMTP SimpleEmailService-2007935501 vtiBU5pQUlPZ3bAZIaZl\n", allow_continue = false
net/smtp.rb:648:in `getok': fmt = "EHLO %s"; args = ["max-thinkpad-linux"]
net/smtp.rb:672:in `check_response': res = "250-email-smtp.amazonaws.com\n250-8BITMIME\n250-SIZE 10485760\n250-STARTTLS\n250-AUTH PLAIN LOGIN\n250 Ok\n", allow_continue = false
net/smtp.rb:648:in `getok': fmt = "STARTTLS"; args = []
net/smtp.rb:672:in `check_response': res = "220 Ready to start TLS\n", allow_continue = false
net/smtp.rb:648:in `getok': fmt = "EHLO %s"; args = ["max-thinkpad-linux"]
net/smtp.rb:672:in `check_response': res = "250-email-smtp.amazonaws.com\n250-8BITMIME\n250-SIZE 10485760\n250-STARTTLS\n250-AUTH PLAIN LOGIN\n250 Ok\n", allow_continue = false
net/smtp.rb:672:in `check_response': res = "334 VXNlcm5hbWU6\n", allow_continue = true
net/smtp.rb:672:in `check_response': res = "334 UGFzc3dvcmQ6\n", allow_continue = true
net/smtp.rb:648:in `getok': fmt = "MAIL FROM:<%s>"; args = ["verified_email1@ourdomain.com"]
net/smtp.rb:672:in `check_response': res = "250 Ok\n", allow_continue = false
net/smtp.rb:648:in `getok': fmt = "RCPT TO:<%s>"; args = ["verified_email2@ourdomain.com"]
net/smtp.rb:672:in `check_response': res = "250 Ok\n", allow_continue = false
net/smtp.rb:672:in `check_response': res = "354 End data with <CR><LF>.<CR><LF>\n", allow_continue = true
net/smtp.rb:672:in `check_response': res = "250 Ok 0102015bd896c863-02370584-903e-4c64-b5a0-5c5c5dcc28c6-000000\n", allow_continue = false
net/smtp.rb:648:in `getok': fmt = "QUIT"; args = []
net/smtp.rb:672:in `check_response': res = "221 Bye\n", allow_continue = false
答案 0 :(得分:0)
问题原来是我的&#34;消息&#34;一部分。
似乎即使我将地址和地址传递给send_message
方法,它们也需要作为标准电子邮件标题进入邮件:将其设置为如下所示工作:
from = "verified_email1@ourdomain.com"
to = "verified_email2@ourdomain.com"
message = <<HEREDOC
Subject: hello
From: #{from}
To: #{to}
Blah Blah Blah
HEREDOC
smtp = Net::SMTP.new options[:address], options[:port]
smtp.enable_starttls
smtp.start Socket.gethostname, options[:user_name], options[:password], options[:authentication] do |server|
server.send_message message, from, to
end
最终,这将由ActionMailer使用,它将为我做所有这些事情。但是,正是测试它在控制台的第一步让我沮丧。