从Rails应用程序发送电子邮件时的Net :: SMTPAuthenticationError(在登台环境中)

eag*_*gor 91 gmail ruby-on-rails ruby-on-rails-3

我正在从我的Rails应用程序发送电子邮件.它在开发环境中运行良好,但在暂存时失败.我收到以下错误:

Net::SMTPAuthenticationError (534-5.7.14 <https://accounts.google.com/ContinueSignIn?plt=AKgnsbtdF0yjrQccTO2D_6)
Run Code Online (Sandbox Code Playgroud)

请注意,我的暂存没有域名.

这是我在staging.rb中的设置

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "my.ip.addr.here:80" }
config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => 'my.ip.addr.here:80'
      :user_name => "my_email_name@gmail.com",
      :password => "my_email_password",
      :authentication => 'login'
}
Run Code Online (Sandbox Code Playgroud)

请帮忙.

编辑.

添加:tls => true选项后,我得到

OpenSSL::SSL::SSLError (Unrecognized SSL message, plaintext connection?)
Run Code Online (Sandbox Code Playgroud)

然后我将端口更改为25,现在我得到了这个(延迟30秒):

Timeout::Error (execution expired)
Run Code Online (Sandbox Code Playgroud)

Gee*_*Bee 240

我遇到了同样的问题:电子邮件是从开发中发送的,但不是来自生产(我在哪里Net::SMTPAuthenticationError).这让我得出结论,问题不是我的应用程序的配置,而是谷歌.

原因:Google阻止了来自未知位置的访问权限(生产中的应用)

解决方案:转到http://www.google.com/accounts/DisplayUnlockCaptcha并单击"继续"(这将为注册新应用授予10分钟的访问权限).在此之后我的生产应用程序开始发送电子邮件;)

  • 此外,请不要忘记允许帐户访问:: https://www.google.com/settings/security/lesssecureapps (40认同)
  • 这实际上是解决问题的正确方法(尽管它可能会使您的帐户面临风险).但它的确有效. (3认同)

A H*_*H K 24

这个解决方案对我有用:

config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host:'localhost', port: '3000' }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"
  config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => 'localhost:3000',
      :user_name => "xyz@gmail.com",
      :password => "password",
      :authentication => :plain,
      :enable_starttls_auto => true
  }
Run Code Online (Sandbox Code Playgroud)

Google确实会阻止您的登录尝试,但您可以通过https://www.google.com/settings/security/lesssecureapps更改设置,以便您的帐户不再受现代安全标准的保护.


eag*_*gor 23

解决了!我只是更改了我的Gmail帐户的密码,不知何故错误消失了.

经过十几次更改后,我最终的最终设置是:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "my.ip.addr.here" }
config.action_mailer.smtp_settings = {
      :address => "smtp.gmail.com",
      :port => 587,
      :domain => 'my.ip.addr.here:80',
      :user_name => "my_email_name@gmail.com",
      :password => "my_email_password",
      :authentication => :plain,
      :enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!这个问题让我很头疼,最后我需要做的是在使用这些设置后更改我的 google 帐户密码,并在 google 帐户设置中设置允许不太安全的应用程序选项。 (2认同)

Sor*_*00b 13

上面的解决方案提供了正确的设置(我已经拥有),但没有解决问题.经过不断的尝试,我不断得到同样的错误.事实证明,我不得不从网上"清除CAPTCHA".有关详细信息,请参阅gmail文档.

您也可以直接跳到了"清除CAPTCHA"页面在这里.


Ben*_*ari 7

我有同样的问题。


解决方案: