2

Good day guys, I am working on a rails application that uses devise to send confirmation emails to registered users. The app properly responds on the development environment and the mails can be caught by mailcatcher. After pushing on heroku my logs reveal a SMTPAuthentication error which leads to a 500 server error each time a user is registered. The logs also reveals that the message gets sent before the error pops up.

2020-02-23T16:04:03.373626+00:00 app[web.1]: 
2020-02-23T16:04:03.373627+00:00 app[web.1]: <p>You can confirm your account email through the link below:</p>
2020-02-23T16:04:03.373627+00:00 app[web.1]: 
2020-02-23T16:04:03.373628+00:00 app[web.1]: <p><a href="https://own-your-life-campaign.herokuapp.com//users/confirmation?confirmation_token=dsbs-bckkBo-qTcuoNLa">Confirm my account</a></p>
2020-02-23T16:04:03.373629+00:00 app[web.1]: 
2020-02-23T16:04:03.373629+00:00 app[web.1]: [12fef5ae-b267-4f98-a4e9-8dd25b6b077b] Completed 500 Internal Server Error in 152ms (ActiveRecord: 5.4ms)
2020-02-23T16:04:03.373630+00:00 app[web.1]: [12fef5ae-b267-4f98-a4e9-8dd25b6b077b]
2020-02-23T16:04:03.373630+00:00 app[web.1]: [12fef5ae-b267-4f98-a4e9-8dd25b6b077b] Net::SMTPAuthenticationError (530-5.7.0 Authentication Required. Learn more at
2020-02-23T16:04:03.373631+00:00 app[web.1]: ):

Here is my action mailler SMTP configuration on my environment/production.rb file.

# ActionMailer Config
  config.action_mailer.default_url_options = { 
    :host => 'https://own-your-life-campaign.herokuapp.com/'
  }

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true

  ActionMailer::Base.smtp_settings = {
   :user_name => ENV['SENDGRID_USERNAME'],
   :password => ENV['SENDGRID_PASSWORD'],
   :domain => 'own-your-life-campaign.herokuapp.com',
   :address => 'smtp.sendgrid.net',
   :port => 587,
   :authentication => :plain,
   :enable_starttls_auto => true
  }

I also added SendGrid addons on heroku and generated a user name and a password, here is a sample of my environment variables on heroku. am omitting my secrete key base and SENDGRID_API key for security reasons.

SECRET_KEY_BASE:          ------------------------------------------------------------------
SENDGRID_API_KEY:         -------------------------------------------------------------------
SENDGRID_PASSWORD:        -------------------------------------
SENDGRID_USERNAME:        --------------------------------------

After creating the SendGrid api key, I verified it on their platform and it gave me a 200 status confirming which is ok. I also changed Api key settings to full access. I don't know if there are further settings I need to do on their platform in other for my post request to properly authenticate from my rails app or It's the fact that am using a Free plan?.

Andre Roy
  • 53
  • 7
  • 2
    Are you sure those credentials are safe to share? Also, in relation to your error, do you have two-factor authentication enabled in SendGrid? – Rockwell Rice Feb 23 '20 at 23:59
  • Concerning securing my credentials, I think it's safe since the sendgrid_api_key itself is not revealed, Thanks for the care. Actually I followed this article https://medium.com/@cheney.shreve/using-devise-with-gmail-sendgrid-rails-and-heroku-tips-to-save-time-debugging-626546118358 to setup SendGrid on Heroku and on the SendGrid platform and did not see anything like two-factor authentication. I will be grateful to receive more insight into that. For now, I think I will google search to know more. – Andre Roy Feb 25 '20 at 00:53
  • I just ran into this error because I set up two factor authentication in Sendgrid and then my connection started failing but I didn't really know why. So I just thought it could be an issue. If it isn't enabled on your sendgrid app then ignore my comment, it is something else. – Rockwell Rice Feb 25 '20 at 14:37
  • Try adding a ":from` property in your`ActionMailer::Base.smtp_settings`, I had to do that also to get it to work. `:from` is the email it gets sent from, so `:from => 'your-email-here@gmail.com',` or whatever it may be. Add that into the `ActionMailer::Base.smtp_settings =` and see if it works then – Rockwell Rice Feb 25 '20 at 14:40
  • Ok Rockwell, I will try that then get back to you. – Andre Roy Feb 26 '20 at 00:32
  • I added this in my smpt settings :from => 'nyagaandreroy@gmail.com' but it still did not work. Still raising authentication issues. – Andre Roy Feb 26 '20 at 21:51

0 Answers0