使用Rails邮件程序的Net :: OpenTimeout(执行过期)异常

时间:2014-10-15 17:04:34

标签: ruby-on-rails smtp actionmailer

我在生产服务器上发送电子邮件时遇到问题。 当邮件程序处理新邮件时,调用异常Net::OpenTimeout (execution expired)

我的smtp设置:

#settings.yml
production:
  smtp:
    address:        smtp.gmail.com
    port:           587
    domain:         mydomain.net
    user_name:      username@gmail.com
    password:       password
    authentication: plain
    enable_starttls_auto: true

我的环境设置:

  #production.rb
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = Settings.smtp.symbolize_keys

来自日志:

Sent mail to username@gmail.com (30010.1ms)
I, [2014-10-15T12:59:22.371563 #19779]  INFO -- : Completed 500 Internal Server Error in 30051ms
F, [2014-10-15T12:59:22.373984 #19779] FATAL -- :.
Net::OpenTimeout (execution expired):
app/controllers/subscribers_controller.rb:9:in `create'

2 个答案:

答案 0 :(得分:7)

我的VPS提供商(DigitalOcean)默认阻止了IPv6上的SMTP :(

我必须在服务器上使用下一个配置禁用IPv6:

# /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1 
net.ipv6.conf.default.disable_ipv6 = 1 
net.ipv6.conf.lo.disable_ipv6 = 1 

应用设置:

$ sysctl -p

取消注释/etc/gai.conf中的下一行,更喜欢IPv4:

precedence ::ffff:0:0/96 100

/etc/resolv.conf删除IPv6 DNS:

nameserver 2001:4860:4860::8844 # remove lines like this 
nameserver 8.8.8.8 #don't remove

然后重启应用程序和Nginx(可选)

答案 1 :(得分:3)

我遇到了同样的问题,在我的情况下,这是因为Google Cloud Compute平台会在端口25,465和587上阻止与Google域外的SMTP服务器的传出连接。

要解决此问题,我们必须连接到非标准SMTP端口(大多数基于API的邮件程序平台也支持2525)。

相关问题