Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Net::OpenTimeout (execution expired) exception with Rails mailer

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:      [email protected]
    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 [email protected] (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'
like image 942
MicRum Avatar asked Oct 15 '14 17:10

MicRum


2 Answers

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)

like image 110
MicRum Avatar answered Nov 19 '22 10:11

MicRum


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).

like image 3
depthfirstdesigner Avatar answered Nov 19 '22 11:11

depthfirstdesigner