0
votes

I am trying to set up the "forgot password" function that comes with devise. I am using rails 5. It always gives me the error: "535-5.7.8 Username and Password not accepted"(Net::SMTPAuthenticationError in Users::PasswordsController#create though.

My code looks like this:

In development.rb I added:

config.action_mailer.default_url_options = { host: 'localhost', port:3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default :charset => "utf-8"

ActionMailer::Base.smtp_settings = {
 :address => "smtp.gmail.com",
 :port => 587,
 :authentication => :plain,
 :domain => 'gmail.com',
 :user_name => '[email protected]',
 :password => 'abcde',
 }

Under config > initialisers > devise.rb I added:

config.mailer_sender = "[email protected]"

and under config > environment.rb:

ActionMailer::Base.delivery_method = :smtp

Am I missing anything or did I do something wrong?

Also another question: I need to link it to my personal account (i.e. replace the user_name and password with the details of a real email account), there is no default devise account the emails get sent from, right? I'm just wondering because like this everyone in my team would be able to see the password of the mail account we're using, right?

Any advice would be highly appreciated! Thanks in advance.

2

2 Answers

2
votes

SMTPAuthenticationError is an error at the SMTP authentication layer.

This means that whatever SMTP service you're trying to use is reporting back some kind of authentication issue.

I do not use Gmail as my SMP, but this error seems strange to me as it says Username and Password not accepted, which is different from incorrect.

Further research shows that Gmail no longer accepts less secure SMTP requests.

Google now doesn't accept login from less secure apps. So you need to go to https://myaccount.google.com/security scroll to the bottom and turn ON "Allow less secure apps: ON". Now when you add the SMTP details to "Send as" google will accept them. You need to do this for the email ID you are adding in your Send as section.

1
votes

I think it's related with your gmail settings. If you see errors like Net::SMTPAuthenticationError while using gmail for sending out emails, visit your gmail settings and enable less secure apps:

"MyAccount" > "Sign-in & security" > "Connected apps & sites" > "Allow less secure apps"