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 => "[email protected]",
:subject => "New Website Contact",
:body => "body",
:message => "message",
:from => "[email protected]"
)
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.
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
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With