【问题标题】:Heroku + Sendgrid = Errno::ECONNREFUSED (Connection refused - connect(2))Heroku + Sendgrid = Errno::ECONNREFUSED(连接被拒绝 - 连接(2))
【发布时间】:2013-10-05 14:44:47
【问题描述】:

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

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

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

这是我目前的设置:

config/initializers/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
}

【问题讨论】:

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


    【解决方案1】:

    应该可以。但是,我已将以下几行添加到 /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。

    【讨论】:

    • 谢谢,但它只是没有发生。我什至复制了您的确切代码,重新检查了插件,并确认 SENDGRID_PASSWORD 和 SENDGRID_USERNAME 存在。仍然出现连接错误。
    • 那么,您在 Heroku 日志中看到了错误,对吧?还是您在本地运行?
    • 谢谢,这确实 最终奏效了。我在上面发布的代码的一个问题是 delivery_method = 'smtp' 而不是 delivery_method = :smtp不会工作。一定有其他的事情我做错了,但我在这方面花了太长时间,所以我们会继续这样做。感谢您的帮助!
    猜你喜欢
    • 2013-08-15
    • 1970-01-01
    • 2012-04-01
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 2016-07-16
    相关资源
    最近更新 更多