Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
959 views
in Technique[技术] by (71.8m points)

smtp - 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:      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'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...