Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

535-5.7.8 Username and Password not accepted

I have a contact form and after submitting I am getting a Net::SMTPAuthenticationError 535-5.7.8 Username and Password not accepted

It's pointing to the create action in the contacts controller ContactMailer.new_contact(@contact).deliver

I have restarted the server. I tried https://accounts.google.com/DisplayUnlockCaptcha.

I am in development.

Contacts controller:

 def new       @contact = Contact.new     end      def create       @contact = Contact.new(params[:message])       if @contact.valid?         ContactMailer.new_contact(@contact).deliver         flash[:notice] = "Message sent! Thank you for contacting us."         redirect_to root_url       else         render :action => 'new'       end     end   end 

Development.rb:

  config.action_mailer.raise_delivery_errors = true   config.action_mailer.perform_deliveries = true   config.action_mailer.delivery_method = :smtp   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  }    config.action_mailer.default_url_options = { :host => "localhost:3000" } 
like image 398
xps15z Avatar asked Apr 17 '14 15:04

xps15z


People also ask

How do you fix 535 5.7 8 username and password not accepted?

If getting "Username and Password not accepted" 535 5.7. 8 error, but user name and password work logging onto email via web (with 2-factor authentication), you may need to enable "Access for less secure apps" (allow exceptions to 2-factor authentication) in your email settings.


Video Answer


2 Answers

I had the same problem. Now its working fine after doing below changes.

https://www.google.com/settings/security/lesssecureapps

You should change the "Access for less secure apps" to Enabled (it was enabled, I changed to disabled and than back to enabled). After a while I could send email.

like image 115
Ravindra Bhalothia Avatar answered Sep 29 '22 14:09

Ravindra Bhalothia


First, You need to use a valid Gmail account with your credentials.

Second, In my app I don't use TLS auto, try without this line:

config.action_mailer.smtp_settings = {   address:              'smtp.gmail.com',   port:                 587,   domain:               'gmail.com',   user_name:            '[email protected]',   password:             'YOUR_PASSWORD',   authentication:       'plain'   # enable_starttls_auto: true   # ^ ^ remove this option ^ ^ } 

UPDATE: (See answer below for details) now you need to enable "less secure apps" on your Google Account

https://myaccount.google.com/lesssecureapps?pli=1

like image 26
MrYoshiji Avatar answered Sep 29 '22 16:09

MrYoshiji