简体   繁体   中英

Devise - "forgot password" function - Username and Password not accepted

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 => 'xyz@gmail.com',
 :password => 'abcde',
 }

Under config > initialisers > devise.rb I added:

config.mailer_sender = "xyz@gmail.com"

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 (ie 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.

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.

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"

Go to your google email account setting and change this settings. and try more than 1 times.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM