535-5.7.8 Username and Password not accepted

42

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" }

This question is tagged with ruby-on-rails

~ Asked on 2014-04-17 15:16:52

The Best Answer is


23

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

~ Answered on 2014-04-17 15:58:27


73

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.

~ Answered on 2015-11-26 07:08:42


Most Viewed Questions: