Home Username and Password not accepted when sending mail (Heroku)
Reply: 0

Username and Password not accepted when sending mail (Heroku)

user1385
1#
user1385 Published in June 20, 2018, 10:51 pm

I'm using ActionMailer to send a confirmation email from my site that's hosted on Heroku. It was working perfectly fine when I typed in my username and password as strings in the smtp_settings, but that's obviously a security flaw since they're up on Github for everyone to see. So today I changed my gmail password and used Heroku's config to save the username and password. My smtp settings now look like this:

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings ={
  address: "smtp.gmail.com",
  port: 587,
  domain: "gmail.com",
  user_name: "#{ENV['EMAIL_USER']}",
  password: "#{ENV['EMAIL_PASS']}",
  authentication: "plain",
  enable_starttls_auto: true
}

Only every time I try to send mail it gives me a "Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted" error. I even added puts to show the values of the config settings in the console:

puts "USERNAME : #{ENV['EMAIL_USER']}"
puts "PASSWORD : #{ENV['EMAIL_PASS']}"

and in Heroku's logs they came out perfectly fine. I read the other post about Gmail blocking the login due to suspicious activity but I've had no such alert. It just doesn't work when I use config variables - changing it back to strings made it work on my local development environment. I'm a bit at a loss here. Any ideas?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304665 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO