连接到gmail时,rails 3.1.0.rc5中的Net :: SMTPAuthenticationError

当我尝试在我的rails应用程序中发送通知时,我收到以下错误

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' 

我的development.rb邮件配置设置是

  # 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' } 

我有这个,它对我有用:

  ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :user_name => "name@example.com", :password => 'password', :authentication => "plain", :enable_starttls_auto => true } 

登录您在浏览器中使用的帐户,然后访问此页面:

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

这样,您就可以使用要访问帐户的应用登录10分钟。 回到你的Rails应用程序并让它发送电子邮件,之后一切都应该工作。

我有一个类似的配置工作正常但偶尔我得到这个错误,我怀疑这是因为谷歌标记该帐户由于某种原因潜在滥用,登录速度太快(每次发送邮件)。

您可以通过Web界面手动登录再次使用它并键入CAPTCHA。 如果经常发生这种情况,我可能会考虑使用其他解决方案,例如使用自己的MTA或至少在Rails和gmail之间的本地MTA,能够发送多封邮件而无需重新登录。 在这种情况下,您甚至可以自己发送邮件,而无需通过Gmail,只需确保设置正确的SPF记录等。

你错过了错误信息中的链接! 🙂

 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 

有关详细信息,请参阅: https : //support.google.com/mail/bin/answer.py?hl = zh-CN&answer = 14257

  • 确保您输入了完整的电子邮件地址(例如username@gmail.com)
  • 确保您的邮件客户端未设置为过于频繁地检查新邮件。 如果您的邮件客户端每10分钟检查一次以上的新邮件,您的客户端可能会反复请求您的用户名和密码。

我遇到了同样的问题:它在我的桌面上工作(在开发环境中),但它在生产环境(瑞典的服务器……)中失败了。 如果Google阻止了登录尝试,您必须登录您的Gmail帐户并查看电子邮件。