Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Net::SMTPAuthenticationError in rails 3.1.0.rc5 when connecting to gmail

When ever time i try sending notifications in my rails app i get the following error

Net::SMTPAuthenticationError (535-5.7.1 Username and Password not accepted. Learn more at                   
):
  app/models/friendship.rb:6:in `send_request'
  app/controllers/friends_controller.rb:21:in `make_friendship'

my development.rb mail config settings is

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = true

  config.action_mailer.delivery_method = :smtp
  # Gmail SMTP server setup
  config.action_mailer.smtp_settings = {
        :address => "smtp.gmail.com",
        :enable_starttls_auto => true,
        :port => 587,
        :domain => '@example.com',
        :authentication => :plain,
        :user_name => '[email protected]',
        :password => 'secret'
  }
like image 792
Uchenna Avatar asked Aug 05 '11 12:08

Uchenna


4 Answers

I have this and it works for me:

  ActionMailer::Base.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :user_name            => "[email protected]",
    :password             => 'password',
    :authentication       => "plain",
    :enable_starttls_auto => true
  }
like image 71
joseph Avatar answered Oct 31 '22 11:10

joseph


Login to the account you're using in your browser then visit this page:

http://www.google.com/accounts/DisplayUnlockCaptcha

This gives you a 10 minute window to login with the app you want to let access your account. Go back to your Rails app and make it send an email, after that everything should work.

like image 29
David Burrows Avatar answered Oct 31 '22 11:10

David Burrows


I have a similar configuration that works fine but once in a while I get this error and I suspect that it is because Google mark the account as potentially abusive for some reason, too fast logins etc (each time a mail is sent).

You can make it work again by manually login via web interface and type the CAPTCHA. If this happens often I would probably think about using some other solution, like using an own MTA or at least an local MTA between Rails and gmail capable of sending multiple mails without relogin. In that case you may even deliver the mail yourself without going thru gmail, just make sure to setup proper SPF records etc.

like image 7
Mattias Wadman Avatar answered Oct 31 '22 13:10

Mattias Wadman


you are missing the link in the error message! :)

Net::SMTPAuthenticationError (535-5.7.1 Username and Password not accepted. Learn more at https://support.google.com/mail/bin/answer.py?hl=en&answer=14257

Thus for details see: https://support.google.com/mail/bin/answer.py?hl=en&answer=14257

  • Make sure that you've entered your full email address (e.g. [email protected])
  • Make sure your mail client isn't set to check for new mail too often. If your mail client checks for new messages more than once every 10 minutes, your client might repeatedly request your username and password.
like image 4
montrealmike Avatar answered Oct 31 '22 11:10

montrealmike