从 Rails 应用程序发送电子邮件时出现 Net::SMTPAuthenticationError(在登台环境中) [英] Net::SMTPAuthenticationError when sending email from Rails app (on staging environment)

查看:49
本文介绍了从 Rails 应用程序发送电子邮件时出现 Net::SMTPAuthenticationError(在登台环境中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am sending email from my Rails application. It works well on development environment, but fails on staging. I get the following error:

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

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

Note, that my I don't have a domain name for my staging.

这是我在 staging.rb 中的设置

Here are my settings in 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'
}

请帮忙.

编辑.

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

After adding :tls => true option I get

OpenSSL::SSL::SSLError (Unrecognized SSL message, plaintext connection?)

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

And then I changed port to 25 and now I get this (with 30 seconds delay):

Timeout::Error (execution expired)

推荐答案

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

I had the same problem: emails were sent from development, but not from production (where I was getting Net::SMTPAuthenticationError). This drove me to conclusion that the problem was not with my app's configuration, but with Google.

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

Reason: Google was blocking access from unknown location (app in production)

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

Solution: Go to http://www.google.com/accounts/DisplayUnlockCaptcha and click continue (this will grant access for 10 minutes for registering new apps). After this my app in production started sending emails ;)

这篇关于从 Rails 应用程序发送电子邮件时出现 Net::SMTPAuthenticationError(在登台环境中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆