2011-12-20 53 views
12

我有一个Rails应用程序配置为通过SMTP使用亚马逊SES。然而,当我尝试发送电子邮件时,它似乎在一分钟后超时,并且出现EOFError。它闻起来像一个配置问题 - 电子邮件似乎构造得很好,我可以从AWS SES控制台发送自己的测试电子邮件。这是沙盒模式,并应用在开发模式下运行,但无论是发送和接收电子邮件已经被证实与SES和development.rb设置了这样的:EOFError错误尝试通过SMTP使用Amazon SES与Rails 3.1.3

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

我已经尝试了百万个配置变体;这开始给我带来香蕉。任何帮助或指导将非常非常感激。更多细节:

的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 [email protected] (59929ms) 
Date: Tue, 20 Dec 2011 03:08:37 -0800 
From: [email protected] 
To: [email protected] 
Message-ID: <[email protected]> 
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' 
+0

请问您的ISP允许端口465出站连接?你可以使用你的亚马逊smtp凭证与普通的邮件客户端? – 2011-12-20 12:16:56

+0

你是否得到这个工作?因为我有同样的问题... – Morten 2012-01-25 15:31:58

+0

还没有得到它的工作 - 通过smpt结束了使用Gmail,这是足够好的暂时。我会在下面尝试Mihir的解决方案并回报(如果有效,请接受答案)。 Frederick,我能够在Rails之外使用smtp - 这是我自己的服务器实例,端口是开放的。 – 2012-01-26 17:25:13

回答

1

SES需要一个SSL会话之前, EHLO命令被发送。

我知道System.Net.Mail不与SES工作,因为System.Net.Mail发起TLS的SMTP会话开始后。

+1

谢谢你的建议,但是如果我正确阅读[this commit](https://github.com/rails/rails/commit/732c724df61bc8b780dc42817625b25a321908e4),ActionMailer(等同于System.Net.Mail的Rails)确实启动了TLS在开始会议之前。 – 2011-12-21 00:07:55

1

我跑进使用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与Rails 2.3 + Ruby 1.8.7兼容的任何确认。我也没有发现任何明确否认它的事情,超出了我的经验&。

让我们知道你是否找到解决方案!

+0

谢谢aws-ses宝石为我工作! – 2012-01-25 08:41:17

6

这里是案件的解决方案要使用SMTP(而不是AWS-SES宝石)

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 

在您的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>” 
} 
+0

当我将模块更改放在与邮件设置相同的文件中时,我得到了这个工作。 – Morten 2012-01-25 15:49:23

+0

对我来说没有运气。 – mixonic 2012-02-08 05:07:38

+3

(On Rails 3.2)我不得不在初始化文件的顶部添加'require'net/smtp''(在'module Net'上面)。我认为它是加载初始化器,然后加载实际的库,覆盖猴子补丁。 – 2012-02-14 18:53:22

10

还有不脱离米希尔猴补丁溶液中的溶液(其中,根据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 
} 
+2

无论出于何种原因使用端口'587'是诀窍。谢谢! – 2013-04-07 19:26:41

+0

根据[docs](http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html),端口465用于ssmtp(smtp over SSL)。对于使用STARTTLS的SMTP,您需要使用您发现的端口25或587。 – AlexT 2014-01-31 10:54:26

+0

谢谢)工作正常 – rusllonrails 2014-12-06 13:00:00

0

我得到这个工作on Rails的3.2.12添加需要“网/ SMTP”来初始化文件中包含的模块变化:

require 'net/smtp' 

    module Net 
    class SMTP 
     def tls? 
     true 
     end 
    end 
end