I'm trying to set up active mailer functionality in my Rails app with Devise and SendGrid so that users can receive a confirmation email when they sign up and can request a forgot password link. When I deploy to Heroku and try and sign up I get an error when I hit 'sign up'. In the Heroku logs the I can see that there is an error as follows:
Completed 500 Internal Server Error in 547ms (ActiveRecord: 8.1ms)
Net::SMTPAuthenticationError (535 Authentication failed: Bad username / password
It's probably something to do with the way I have my config files but I can't put my finger on it. Any help would be massively appreciated! Here are my files.
config/application.yml
production:
SECRET_KEY_BASE: <%= ENV["SECRET_KEY_BASE"] %>
development:
GMAIL_USERNAME: [email protected]
GMAIL_PASSWORD: password
SENDGRID_USERNAME: [email protected]
SENDGRID_PASSWORD: password
test:
GMAIL_USERNAME: [email protected]
GMAIL_PASSWORD: password
SENDGRID_USERNAME: [email protected]
SENDGRID_PASSWORD: password
production:
GMAIL_USERNAME: [email protected]
GMAIL_PASSWORD: password
SENDGRID_USERNAME: [email protected]
SENDGRID_PASSWORD: password
I'm using the figaro gem to manage my environment variables.
Your problem appears to be that you're referencing
GMAIL_USERNAMEandGMAIL_PASSWORDinstead ofSENDGRID_USERNAMEandSENDGRID_PASSWORD, and you're still referencing the Gmail SMTP server and port.Assuming you're using this gem: https://github.com/stephenb/sendgrid, this should do the trick for your production config file:
Update: per you comment that you're using the
figarogem, make sure to run the rake task that adds theENVvariables to Heroku:rake figaro:heroku