【问题标题】:SendGrid on Heroku failsHeroku 上的 SendGrid 失败
【发布时间】:2012-04-07 03:40:22
【问题描述】:

我为我的 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 来获取实际的密码和用户名并对其进行硬编码,但仍然给了我同样的错误。

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-3.2


【解决方案1】:

RoR + SendGrid + Heroku:

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

我试过了

  • 我在 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/

【讨论】:

  • 对我来说是apikey(全部小写)
  • @stevec 你是对的,我已经编辑了我的答案。谢谢!
【解决方案2】:

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

heroku config:add SENDGRID_PASSWORD=my-new-password

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

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

【讨论】:

  • 澄清一下,heroku config:addheroku config:set 只是在 Heroku 堆栈上设置一个环境变量。在 Ruby 中,您可以使用 ENV['SENDGRID_PASSWORD'] 访问它。您还可以在 Heroku 上查看环境变量的值:heroku config:get SENDGRID_PASSWORD
猜你喜欢
  • 1970-01-01
  • 2018-04-01
  • 1970-01-01
  • 2021-07-19
  • 2019-11-04
  • 2023-01-31
  • 1970-01-01
  • 1970-01-01
  • 2013-10-28
相关资源
最近更新 更多