问题
I have problem with delivering emails on production server.
When mailer processed new message, calls exception Net::OpenTimeout (execution expired)
My smtp settings:
#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
My environment settings:
#production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = Settings.smtp.symbolize_keys
From logs:
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'
回答1:
My VPS provider (DigitalOcean) blocked SMTP on IPv6 by default :(
I had to disable IPv6 on server with next config:
# /etc/sysctl.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
Apply settings:
$ sysctl -p
Uncomment the next line in /etc/gai.conf
to prefer IPv4:
precedence ::ffff:0:0/96 100
And remove IPv6 DNS from /etc/resolv.conf
:
nameserver 2001:4860:4860::8844 # remove lines like this
nameserver 8.8.8.8 #don't remove
Then restart application and Nginx (optional)
回答2:
I had the same issue, in my case it was because Google Cloud Compute platform blocks outgoing connections to SMTP servers outside of Google's domain on ports 25, 465, and 587.
To fix this problem we had to connect to a non-standard SMTP port (most API-based mailer platforms support 2525 as well for this reason).
来源:https://stackoverflow.com/questions/26388090/netopentimeout-execution-expired-exception-with-rails-mailer