我一直在拼命尝试使用RoR中的Action Mailer类发送电子邮件,即使终端显示正在发送消息,它仍会返回此错误:
et::SMTPAuthenticationError: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbtOS
from /Users/abhasarya/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:968:in `check_auth_response'
from /Users/abhasarya/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:739:in `auth_plain'
from /Users/abhasarya/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:731:in `authenticate'...
这是我的mailer类在app / mailers / my_mailer.rb中的样子:
class MyMailer < ActionMailer::Base
default from: "[email protected]"
def welcome_email(user)
@user = user
mail(to: user.email,
from: '[email protected]',
subject: 'Welcome!')
end
end
这是我的config / application.rb文件的样子:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
#domain: 'gmail.com',
user_name: '[email protected]',
password: 'my_password',
authentication: 'plain',
enable_starttls_auto: true
}
config.action_mailer.default_url_options = {
:host => "localhost",
:port => 3000
}
在我的config / environments / development.rb文件中,我也有这两行:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
我的问题是,每当我启动rails控制台(在开发中工作,不知道如何在生产中运行)时,都将用户的电子邮件分配给user变量,然后输入以下命令: MyMailer.welcome_email(user).deliver
终端说:
Rendered my_mailer/welcome_email.html.erb (11.7ms)
Rendered my_mailer/welcome_email.text.erb (0.5ms)
Sent mail to [email protected] (923.1ms)
Date: Fri, 08 Aug 2014 13:54:38 -0400
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Welcome!
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_53e50eded7355_2b0b8082dbf85068f";
charset=UTF-8
Content-Transfer-Encoding: 7bit
但是会导致错误。我的观点很简单,以至于我认为不需要在这里包含它们。我拼命尝试了一切,包括解锁Google验证码,但仍然无济于事。非常感谢您的帮助,我所希望的只是将一封电子邮件发送到正确的收件箱。如果您能解决这个问题,我将永远爱您!!!
您看到此错误的原因是Google阻止了您的IP。您将需要为此IP启用授权。
转到http://www.google.com/accounts/DisplayUnlockCaptcha,然后单击继续。
然后再次尝试从应用程序发送电子邮件,它应该可以工作。您需要在访问上述链接的10分钟内从您的应用发送电子邮件。通过访问以上链接,Google将授予10分钟的注册新应用的权限。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句