7
votes

I'm pretty sure I have everythign configured right, but I keep getting 'Net::SMTPAuthenticationError: 535-5.7.8 Username and Password not accepted. Learn more at' error when trying to send mails through my rails app. Also, there is only a blank space after the 'at' in the error message so I don't even know where to look for more information. I am also 100% sure the password and email are correct.

in my config/development.rb (I also have this in application.rb)

  config.action_mailer.delivery_method = :smtp
 # SMTP settings for gmail

config.action_mailer.smtp_settings = { 

 :address              => 'smtp.gmail.com',
 :port                 => 587,
 :domain               => 'gmail.com',
 :user_name            => '[email protected]',
 :password             => 'password',
 :authentication       => 'plain',
:enable_starttls_auto => true
}

I have allowed less secure apps access on the actual gmail account.

2
Are you using 2F authentication?reducing activity
Yes, I'm having the same issue also i tried port 465Ezio Auditore

2 Answers

13
votes

Google blocks all suspicious login attempts. By using app password, I was able to solve the problem:

  1. Enable 2-Step Verification if you haven't done so.
  2. Go to App passwords (Google will ask you to login again to verify here)
  3. Create a new App password: Choose Other (Custom name) under Select app, then enter app's name (any name you want)
  4. Click generate, a popup will be shown with a password. Use that password in your rails configuration instead of your google password.
5
votes

This is the config that works for me with Google apps for business. Try changing your port to 465

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  tls: true,
  address:              ENV["EMAIL_URL"],
  port:                 465,
  domain:               ENV["EMAIL_DOMAIN"],
  user_name:            ENV["EMAIL_USER_NAME"],
  password:             ENV["EMAIL_PASSWORD"],
  authentication:       'plain',
  enable_starttls_auto: true  }