Errno::ECONNREFUSED (Connection refused - connect(

2019-07-22 14:04发布

问题:

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
    }

回答1:

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