Net::SMTPAuthenticationError in rails 3.1.0.rc5 wh

2019-01-22 21:18发布

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

5条回答
We Are One
2楼-- · 2019-01-22 21:35

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.

查看更多
干净又极端
3楼-- · 2019-01-22 21:45

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.

查看更多
Emotional °昔
4楼-- · 2019-01-22 21:56

I have this and it works for me:

  ActionMailer::Base.smtp_settings = {
    :address              => "smtp.gmail.com",
    :port                 => 587,
    :user_name            => "name@example.com",
    :password             => 'password',
    :authentication       => "plain",
    :enable_starttls_auto => true
  }
查看更多
相关推荐>>
5楼-- · 2019-01-22 21:56

I had the same problem: it worked from my desktop (in development environment), but it failed from production environment (a server in Sweden...). You have to login into your gmail account and check the emails if Google has prevented the sign-in attempt.

查看更多
Deceive 欺骗
6楼-- · 2019-01-22 22:00

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. username@gmail.com)
  • 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.
查看更多
登录 后发表回答