通过 Sendgrid 和 Heroku 部署时,Action Mailer production.rb 不工作

Action Mailer production.rb not working when deployed via Sendgrid and Heroku

我目前正在尝试向在我的 Rails 应用程序上创建帐户的任何新用户发送帐户确认电子邮件。

我已经通过 development.rb 在本地成功部署,但出于某种原因,我每次 "We're sorry, but something went wrong. If you are the application owner check the logs for more information" 都会收到一条错误消息。我在 Stack Overflow 以及 Heroku、Youtube 上查看了一些资源,但未能找到解决方案。

这是我在 environments/production.rb:

中的代码
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "smtp.sendgrid.net",
port: 587,
domain: ENV["SENDGRID_DOMAIN"],
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["SENDGRID_USERNAME"],
password: ENV["SENDGRID_PASSWORD"]
}

config.action_mailer.default_url_options = {:host => "<myherokuappname>.herokuapp.com/"}


config.action_mailer.perform_caching = false

再次确认一下,我可以在本地部署电子邮件,只是不能在生产级别部署。任何提示将不胜感激。

我最近也将 SendGrid 集成到了我的 Heroku 应用程序中。我的production.rb设置如下:

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

我刚刚在几分钟前测试过它,发送正常。