0

我正在尝试让 Heroku Sendgrid 插件与我的 Rails 应用程序一起使用,但不断出现连接错误:

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

我已经查看了与此相关的其他 SO 问题,但提供的解决方案- 将 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
}
4

1 回答 1

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。

于 2013-10-05T16:12:28.803 回答