2

我为我的 Heroku 帐户设置了 Sendgrid,但是当应用程序尝试发送邮件时日志显示以下问题:

Net::SMTPFatalError(550 无法从指定地址接收<[我在 devise.rb 中使用 config.mailer_sender 指定的电子邮件地址]>:不允许未经身份验证的发件人

我的 production.rb 设置是:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { :host => 'heroku.com' }

  config.action_mailer.smtp_settings = {
    address: "smtp.sendgrid.net",
    port: 587,
    authentication: "plain",
    user_name: ENV["my sendgrid username"],
    password: ENV["my sendgrid password"],
    domain: 'heroku.com'
  }

我的 Sendgrid 密码/用户名是使用 Heroku 从 Heroku 获得的heroku config -long

有人对问题可能出在哪里有任何建议吗?如何授予我在 config.mailer_sender 身份验证中定义的电子邮件地址?

4

1 回答 1

8

您的用户名和密码必须是键名,而不是值:

config.action_mailer.smtp_settings = {
    address: "smtp.sendgrid.net",
    port: 587,
    authentication: "plain",
    user_name: ENV["SENDGRID_USERNAME"],
    password: ENV["SENDGRID_PASSWORD"],
    domain: 'heroku.com'
  }

这个想法是您将配置与您的代码分开

于 2012-02-09T16:22:18.180 回答