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

我在生产服务器上发送电子邮件时遇到问题。 邮件处理新邮件时,调用exceptionNet::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' 

我的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的下一行以/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(可选)

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

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