Heroku + Sendgrid = Errno :: ECONNREFUSED(连接被拒绝 - 连接(2))

时间:2013-10-05 14:44:47

标签: ruby-on-rails email heroku actionmailer sendgrid

我正在尝试使用我的Rails应用程序使用Heroku Sendgrid插件,但继续发生连接错误:

Errno::ECONNREFUSED (Connection refused - connect(2)):

我已经查看了与此相关的其他SO问题,但是solution offered - 将ActionMailer配置从环境文件移动到初始化程序 - 并没有为我解决任何问题。

这是我目前的设置:

配置/初始化/ smtp.rb:

ActionMailer::Base.default_url_options =  { host: 'http://my-app.herokuapp.com/'}
ActionMailer::Base.delivery_method = 'smtp'
ActionMailer::Base.smtp_settings = {
  :user_name => ENV['SENDGRID_USERNAME'],
  :password => ENV['SENDGRID_PASSWORD'],
  :domain => 'heroku.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

1 个答案:

答案 0 :(得分:4)

那应该有用。但是,我已将以下行添加到/environments/productions.rb以使我的工作正常运行。

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
          :address        => 'smtp.sendgrid.net',
          :port           => '587',
          :authentication => :plain,
          :user_name      => ENV['SENDGRID_USERNAME'],
          :password       => ENV['SENDGRID_PASSWORD'],
          :domain         => 'heroku.com'
  }
  config.action_mailer.default_url_options = { :host => 'your_domain.com' }

并确保在Heroku上为您的应用正确设置SendGrid插件。

您可以检查是否在Heroku上正确配置了SendGrid:

$ heroku config

您应该看到SENDGRID_PASSWORD和SENDGRID_USERNAME。