7

我为我的 heroku 应用程序设置了发送网格启动器。

我把它放在我的 config/environment.rb 中:

ActionMailer::Base.smtp_settings = {
  :user_name => ENV["SENDGRID_USERNAME"],
  :password => ENV["SENDGRID_PASSWORD"],
  :domain => "my-sites-domain.com",
  :address => "smtp.sendgrid.net",
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

我创建了这个类models/notifier.rb:

class Notifier < ActionMailer::Base

  def notify()
    mail( 
      :to => "my-email@gmail.com",
      :subject => "New Website Contact",
      :body => "body",
      :message => "message",
      :from => "website@my-sites-domain.com"
    )
  end

end

我把它放在另一个控制器中发送电子邮件:

def contact
  Notifier.notify().deliver
  redirect_to("/", :notice => "We Have Received Your Request And Will Contact You Soon.")
end

当我部署并尝试发送电子邮件时,我收到此错误:

Net::SMTPAuthenticationError(535 身份验证失败:用户名/密码错误

我已经完全设置了发送网格,它说我准备好发送电子邮件了。

我还跑去heroku config --long获取实际的密码和用户名并对其进行硬编码,但这仍然给了我同样的错误。

4

2 回答 2

5

RoR + SendGrid + Heroku:

我遇到了类似的问题,我一直收到这个错误 Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password when I尝试发送电子邮件。

我试过

  • 我在 sendgrid 上注册的用户名,以及
  • 也是生成的一个heroku(当我委托插件时)。

答案很简单。

不要使用任何用户名。它是简单的文本'apikey',密码使用您从仪表板获得的生成的 API 密钥。

更多在这里 # https://support.sendgrid.com/hc/en-us

我的 SMTP 用户名和密码是什么?

我们建议使用“apikey”作为您的 SMTP 用户名并创建一个 API 密钥用于您的密码。欲了解更多信息,请点击此处。 https://sendgrid.com/docs/for-developers/sending-email/integrating-with-the-smtp-api/

于 2021-01-21T05:22:32.390 回答
3

我曾尝试使用以下命令设置密码:

heroku config:add SENDGRID_PASSWORD=my-new-password

但事实证明,这只更改了 heroku 存储为您的密码的内容,实际上并没有更改您的密码。执行此操作后,您也无法找回密码。

我必须做的是删除并重新添加 sendgrid 插件。

于 2012-04-07T21:47:10.990 回答