SendGrid + Ruby on Rails 6 on DigitalOcean Apps + Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):

SendGrid + Ruby on Rails 6 on DigitalOcean Apps + Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):

我认为这个错误是关于 ENV API 密钥的。这在我的本地主机上运行良好,但在服务器上运行良好。

我将 API 密钥添加到 组件/环境变量:

和我的 development.rb 文件。如下:

  config.action_mailer.delivery_method = :smtp
  ActionMailer::Base.smtp_settings = {
    :address        => "smtp.sendgrid.net",
    :port           => "587",
    :authentication => :plain,
    :user_name      => 'apikey',
    :password       => ENV['SENDGRID_API_KEY']
  }

我仍然得到如下错误

Errno::ECONNREFUSED(连接被拒绝 - “localhost”端口 25 的连接(2)):

唉!浪费了2天的时间。我所要做的就是将 Actionmailer 设置添加到

production.rb

我之前只在 development.rb 文件中有它。呸!!