Ruby-on-rails 从 Rails 应用程序发送电子邮件时出现 Net::SMTPAuthenticationError(在登台环境中)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18124878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Net::SMTPAuthenticationError when sending email from Rails app (on staging environment)
提问by eagor
I am sending email from my Rails application. It works well on development environment, but fails on staging. I get the following error:
我正在从我的 Rails 应用程序发送电子邮件。它在开发环境中运行良好,但在登台上失败。我收到以下错误:
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.
请注意,我没有用于登台的域名。
Here are my settings in staging.rb
这是我在 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 => "[email protected]",
:password => "my_email_password",
:authentication => 'login'
}
Please, help.
请帮忙。
Edit.
编辑。
After adding :tls => trueoption I get
添加:tls => true选项后我得到
OpenSSL::SSL::SSLError (Unrecognized SSL message, plaintext connection?)
And then I changed port to 25 and now I get this (with 30 seconds delay):
然后我将端口更改为 25,现在我得到了这个(延迟了 30 秒):
Timeout::Error (execution expired)
回答by Gee-Bee
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.
我遇到了同样的问题:电子邮件是从开发中发送的,而不是从生产中发送的(我在那里收到Net::SMTPAuthenticationError)。这让我得出结论,问题不在于我的应用程序的配置,而在于 Google。
Reason: Google was blocking access from unknown location (app in production)
原因:Google 阻止了来自未知位置的访问(生产中的应用程序)
Solution: Go to http://www.google.com/accounts/DisplayUnlockCaptchaand click continue (this will grant access for 10 minutes for registering new apps). After this my app in production started sending emails ;)
解决方案:转到http://www.google.com/accounts/DisplayUnlockCaptcha并单击继续(这将授予 10 分钟的访问权限以注册新应用程序)。在此之后,我的生产应用程序开始发送电子邮件;)
回答by eagor
Solved! I simply changed passwordfor my gmail account and somehow errors disappeared.
解决了!我只是更改了我的 gmail 帐户的密码,不知何故错误消失了。
After dozen of changes, the final settings I ended up with are:
经过十几次更改,我最终得到的最终设置是:
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 => "[email protected]",
:password => "my_email_password",
:authentication => :plain,
:enable_starttls_auto => true
}
回答by A H K
This solution is working for me:
这个解决方案对我有用:
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 => "[email protected]",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true
}
It's true that Google will block your sign-in attempt but You can change your settings at https://www.google.com/settings/security/lesssecureappsso that your account is no longer protected by modern security standards.
Google 确实会阻止您的登录尝试,但您可以在https://www.google.com/settings/security/lesssecureapps更改您的设置,以便您的帐户不再受现代安全标准的保护。
回答by aashish
go to following link and turn on https://www.google.com/settings/security/lesssecureapps
转到以下链接并打开 https://www.google.com/settings/security/lesssecureapps
回答by Sorry-Im-a-N00b
The above solution provided the correct settings (which I already had) but did not solve the issue. After continued attempts, I kept getting the same error. Turns out, I had to "clear the CAPTCHA" from the web. See the gmail documentationfor details.
上述解决方案提供了正确的设置(我已经有了)但没有解决问题。经过不断的尝试,我不断收到同样的错误。原来,我不得不从网上“清除验证码”。有关详细信息,请参阅gmail 文档。
You can also jump right to the "clear the CAPTCHA" page here.
您也可以直接跳转到“清除CAPTCHA”页面在这里。
回答by Alejandro Sherwell
A lot later but just in case it helps anyone.. Just called Google Apps Help Center and they instructed to change the lesssecureapps setting (as everyone else) but also to change the port to 465.
很久以后,但以防万一它对任何人有帮助。 刚刚打电话给 Google Apps 帮助中心,他们指示更改 lesssecureapps 设置(与其他人一样),但也将端口更改为 465。
In my case, that did the trick!
在我的情况下,这成功了!
回答by Benyamin Jafari
I had the same problem.
我有同样的问题。
Solution:
解决方案:
You can turn on
less secure appsoption (at here).
https://myaccount.google.com/lesssecureappsAnd unlock Captcha(link):
https://accounts.google.com/DisplayUnlockCaptcha
您可以打开
less secure apps选项(在此处)。
https://myaccount.google.com/lesssecureapps并解锁验证码(链接):https:
//accounts.google.com/DisplayUnlockCaptcha
回答by ubugnu
The accepted answer seems very old, I don't know if at that time the followin (better) solution was existing:
接受的答案似乎很旧,我不知道当时是否存在以下(更好的)解决方案:
- Go to https://myaccount.google.com/u/0/apppasswords
- Generate a new password for you app
- Replace the personal password with the generated password in
config.action_mailer.smtp_settings
- 转到https://myaccount.google.com/u/0/apppasswords
- 为您的应用生成新密码
- 用生成的密码替换个人密码
config.action_mailer.smtp_settings
Now, sending emails works perfectly!
现在,发送电子邮件完美无缺!
回答by cooxy
Hello this also worked for me and so if someone is still having a problem try this out.
你好,这对我也有用,所以如果有人仍然有问题,试试这个。
Make sure you have figaro in your gemfile. To save sensitive information such as username and password as environment variables
确保您的 gemfile 中有 figaro。将用户名和密码等敏感信息保存为环境变量
gem 'figaro'
And in your config/environments/development.rb , paste the codes below using smtp as method delivery
并在您的 config/environments/development.rb 中,使用 smtp 作为方法交付粘贴以下代码
config.action_mailer.delivery_method = :smtp
SMTP settings for gmail
Gmail 的 SMTP 设置
config.action_mailer.smtp_settings =
{
:address=> "smtp.gmail.com",
:port => 587,
:user_name => ENV['gmail_username'],
:password=> ENV['gmail_password'],
:authentication=> "plain",
:enable_starttls_auto=>true
}
config.action_mailer.default_url_options = { host: "locahost:3000" }
In your config directory create a file called application.yml and add the codes below.
在您的 config 目录中创建一个名为 application.yml 的文件并添加以下代码。
gmail_username: '[email protected]'
gmail_password: "your_example_email_password_here"
You must use your email and password for authentication in the file.
您必须使用您的电子邮件和密码在文件中进行身份验证。
回答by Shrinivas
I also faced the problem, and after some research in Gmail setting, I found the solution:
我也遇到了这个问题,经过对 Gmail 设置的一些研究,我找到了解决方案:
In gmail, go to settings.
Select "Forwarding and POP/IMAP" tab.
In the IMAP access section, select "Enable IMAP".
在 Gmail 中,转到设置。
选择“转发和 POP/IMAP”选项卡。
在 IMAP 访问部分,选择“启用 IMAP”。

