ruby-on-rails EOFError尝试通过SMTP将Amazon SES与Rails 3.1.3配合使用时出错

kx1ctssn  于 2023-02-17  发布在  Ruby
关注(0)|答案(5)|浏览(192)

我有一个Rails应用程序被配置为通过SMTP使用Amazon SES。不过,当我尝试发送电子邮件时,它似乎在一分钟后超时,我得到了一个EOFError。这闻起来像是配置问题--电子邮件似乎构造得很好,我可以从AWS SES控制台向自己发送测试电子邮件。这是在沙盒模式下,应用程序运行在开发模式下,但是发送和接收的电子邮件都经过SES验证,development.rb是这样设置的:

config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp

我试过上百万种配置这开始让我发疯了。2任何帮助或指导都将非常非常感激。3更多细节:
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"
 }

包含错误的日志,为简洁起见,略做截断:

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'
qoefvg9y

qoefvg9y1#

还有一种解决方案没有Mihir的monkey-patch解决方案(根据AWS SES文档,http://docs.amazonwebservices.com/ses/latest/DeveloperGuide/SMTP.Connecting.html是TLS Package 器解决方案),而是使用端口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
}
xxb16uws

xxb16uws2#

如果您想使用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,并将以下代码添加到货币补丁ActionMailer的SMTP设置中。

module Net
    class SMTP
        def tls?
            true
        end
    end
end

在您的开发. rb和生产. 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>”
}
vohkndzv

vohkndzv3#

我在使用Rails 2.3和Ruby 1.8.7时遇到了同样的问题,在开发模式下使用沙箱SES帐户,向/从经过验证的发件人发送邮件。
我通过添加unofficial aws-ses gem来解决这个问题。将它粘贴到您的Gemfile中,然后用以下5行替换smtp设置:

# Configure mail sending options: Use AWS-SES for all environments
  config.after_initialize do
    ActionMailer::Base.delivery_method = :amazon_ses
    ActionMailer::Base.custom_amazon_ses_mailer = AWS::SES::Base.new(:secret_access_key => 'asfd/1234', :access_key_id => 'ABCD')
  end

发送然后按预期工作...这告诉我电子邮件本身得到了正确的设置。
我在谷歌上搜索了很多,没有看到任何关于SES-SMTP与Rails2.3 + Ruby1.8.7兼容的确认,也没有发现任何明确否认这一点的东西,超出了你和我的经验。
如果您找到解决方案,请告诉我们!

3pmvbmvn

3pmvbmvn4#

SES要求在发送EHLO命令之前进行SSL会话。
我知道System.Net.Mail不能与SES一起工作,因为System.Net.Mail在SMTP会话启动后启动TLS。

mlnl4t2r

mlnl4t2r5#

我在Rails3.2.12中使用了这个方法,将require 'net/smtp'添加到初始化文件中,模块更改如下:

require 'net/smtp'

  module Net
    class SMTP
      def tls?
        true
      end
    end
 end

相关问题