Search code examples
ruby-on-railsemaildeploymenttelnetsidekiq

Net::OpenTimeout (execution expired) exception on Sidekiq


I'm using sidekiq to to queue the emails my Rails application will send. Sending emails works in development, but in production sidekiq will get a network timeout error. What's going on?

Here's my config in production.rb

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address:              'smtp.gmail.com',
  port:                 578,
  domain:               ENV["PPRODUCTION_DOMAIN"],
  user_name:            ENV["GMAIL_USERNAME"],
  password:             ENV["GMAIL_PASSWORD"],
  authentication:       :plain,
  enable_starttls_auto: true
}

config.active_job.queue_adapter = :sidekiq

I have tried the following:

  1. Disabling IPv6 and setting IPv4 as the preferred
  2. Using a non-standard port (2525) instead of 587
  3. Tried connecting via telnet smtp.gmail.com 587. I get the following error: telnet: Unable to connect to remote host: Network is unreachable. It might be worth noting that I'm operating behind a proxy - should there be an additional setup in this case?
  4. sudo ufw allow 587

I'm on an Ubuntu 14.04 server and have set up my app using unicorn and nginx.

I've been at this for days. :( Any help would be greatly appreciated!

Update:

I also tried the following:

  1. Remove sidekiq to send the email using Rails' mailer instead. Same results.
  2. Connect via telnet smtp.gmail.com 465. This one works so I tried setting the port in production to 465, but I still get the same error.
  3. Remove the domain, using our production domain, and using localhost:3000. Nothing happens.

Solution

  • Somehow fixed it by changing the port to 456 instead.

    I changed the port because for some reason, telnet smtp.gmail.com 587 doesn't work but telnet smtp.gmail.com 465 does. 587 may have been blocked by the network.

    Also, I'm not sure if the following changes also helped, but I also changed the authentication to :login instead of :plain and added ssl: true. Hope this helps out anyone who encounters the same problem.