关于Heroku错误的Sendgrid

Und*_*ion 2 email smtp ruby-on-rails heroku sendgrid

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

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

我的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'
  }
Run Code Online (Sandbox Code Playgroud)

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

有没有人对问题所在的位置有任何建议?如何授予我在config.mailer_sender身份验证中定义的电子邮件地址?

Nei*_*ton 8

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

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'
  }
Run Code Online (Sandbox Code Playgroud)

我们的想法是将配置与代码分开.