SendGrid on Heroku fails

自古美人都是妖i 提交于 2021-02-16 16:37:32

问题


I setup send grid starter for my heroku app.

I put this in my 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
}

I create this class 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

I put this in another controller to send the email:

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

When I deploy and try to send an email I get this error:

Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password

I have setup send grid completely and it says I am ready to send emails.

I also ran heroku config --long to get the actual password and user name and hard coded them and that still gave me the same error.


回答1:


I had tried to set my password with the command:

heroku config:add SENDGRID_PASSWORD=my-new-password

But it turns out this only changes what heroku has stored as your password, it doesn't actually change your password. You also cannot retrieve your password after doing this.

What I had to do was remove and re-add the sendgrid add on.




回答2:


RoR + SendGrid + Heroku:

I came across similar problem where I kept receiving this error Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password when I was trying to send email.

I tried

  • username with which I signed up with sendgrid, and
  • also the one heroku generated (when I commissioned the addon).

Answer is very simple.

DO not use any username. It is simple text 'apikey' and for password use the generated API key that you got from Dashboard.

More here # https://support.sendgrid.com/hc/en-us

What is my SMTP Username and Password?

We recommend using "apikey" for your SMTP username and creating an API Key to use for your password. For more information, click here. https://sendgrid.com/docs/for-developers/sending-email/integrating-with-the-smtp-api/



来源:https://stackoverflow.com/questions/10051537/sendgrid-on-heroku-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!