3

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
    }
Community
  • 1
  • 1
Brock Klein
  • 317
  • 4
  • 11
  • 1
    Sounds like `ENV['SES_ADDRESS']` is nil - are you sure that environment variable is set? – Frederick Cheung Jul 30 '16 at 20:26
  • Can you paste the out put of this command telnet myappname.herokuapp.com 587 from your production environment – Piyush Patil Jul 30 '16 at 20:41
  • Of course...you're 100% right @FrederickCheung. Been so long since I deployed new ENV variables to Heroku that I forgot that I was using Figaro and needed to run `figaro heroku:set -e production` to sync everything up. I'm golden now. Thanks for the suggestion. If you want to submit I'll accept - otherwise I'll accept alexandresaiz since it's a similar observation. – Brock Klein Jul 30 '16 at 23:12

1 Answers1

2

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

alexandresaiz
  • 2,678
  • 7
  • 29
  • 40