【问题标题】:Net::OpenTimeout (execution expired) exception with Rails mailer带有 Rails 邮件程序的 Net::OpenTimeout(执行过期)异常
【发布时间】:2014-12-10 20:34:27
【问题描述】:

我在生产服务器上发送电子邮件时遇到问题。 当邮件程序处理新消息时,调用异常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'

【问题讨论】:

  • 我认为,我的 VPS 上的 ipv6 配置有问题。当我尝试从终端命令telnet smtp.gmail.com 587 调用时,连接大约需要 1 分钟

标签: ruby-on-rails smtp actionmailer


【解决方案1】:

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

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

【讨论】:

  • 端口 25 为我工作。我尝试了很多端口,这可能取决于您的 ISP 或其他什么...不是这方面的专家。
【解决方案2】:

默认情况下,我的 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(可选)

【讨论】:

  • 我做到了,但 telnet smtp.gmail.com 465telnet smtp.gmail.com 587 仍然不起作用..
  • 执行此操作后,我无法在服务器上部署,出现错误#<:runner::executeerror: exception while execution as root exit>
  • 端口 25 为我工作。我尝试了很多端口,这可能取决于您的 ISP 或其他什么...不是这方面的专家。
  • 它帮助我解决了迁移后从 Rails App 发送电子邮件的问题。
猜你喜欢
  • 2014-05-19
  • 2020-05-14
  • 1970-01-01
  • 1970-01-01
  • 2013-07-24
  • 1970-01-01
  • 2019-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多