簡體   English   中英

使用Rails郵件程序的Net :: OpenTimeout(執行過期)異常

[英]Net::OpenTimeout (execution expired) exception with Rails mailer

我在生產服務器上發送電子郵件時遇到問題。 當郵件程序處理新郵件時,調用異常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提供商(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)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM