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

帅比萌擦擦* 提交于 2019-12-13 16:15:19

问题


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.



来源:https://stackoverflow.com/questions/38677793/errnoeconnrefused-connection-refused-connect2-for-nil-port-587-for-rail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!