Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errno::ECONNREFUSED (Connection refused - connect(2) for nil port 587): for Rails on Heroku

I suspect I'm missing something basic here, but been wrestling with this one for a while with no luck.

Rails 4.2.5
Ruby 2.2.3p173

Emails are sending fine on localhost using Amazon SES (I followed this stellar guide) but not on a Heroku production environment. I'm receiving the error in the title of the post:

Errno::ECONNREFUSED (Connection refused - connect(2) for nil port 587)

I suspect the core of the problem is the nil in there, but I haven't been able to figure out where it's coming from. No one else seems to have that problem and even debug level logs don't give me anything more to work with.

I've read dozens of posts like this. But my configurations match all spec as far as I can tell.

Any help/recommendations would be much appreciated.

development.rb

# Devise
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

  # Configure mailer
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"

    config.action_mailer.smtp_settings = {
      :address => ENV['SES_ADDRESS'],
      :port => 587,
      :enable_starttls_auto => true,
      :user_name => ENV['SES_ACCESS_KEY_ID'],
      :password => ENV['SES_SECRET'],
      :authentication => :login
    }

production.rb

 # Devise
  config.action_mailer.default_url_options = { :host => 'myappname.herokuapp.com'}

  # Configure mailer
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"

    config.action_mailer.smtp_settings = {
      :address => ENV['SES_ADDRESS'],
      :port => 587,
      :enable_starttls_auto => true,
      :user_name => ENV['SES_ACCESS_KEY_ID'],
      :password => ENV['SES_SECRET'],
      :authentication => :login
    }
like image 917
Brock Klein Avatar asked Oct 31 '25 13:10

Brock Klein


1 Answers

Set your environment variables, make sure your SES endpoint is in production mode and you should be good.

like image 118
alexandresaiz Avatar answered Nov 03 '25 03:11

alexandresaiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!