问题描述
|
服务器指出电子邮件已发送到正确的地址,但是收件箱中没有收到该消息。
我的Setup_mail.rb文件
ActionMailer::Base.smtp_settings ={
:address => \"smtp.gmail.com\",:port => 587,:domain => \"gmail.com\",:user_name => \"my_user_name@gmail.com\",:password => \"my_password\",:authentication => \"Plain\",:enable_starttls_auto => true
}
我的development.rb
文件是:
# Don\'t care if the mailer can\'t send
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true #default value
config.action_mailer.delivery_method = :smtp #default value
我的test.rb
文件是:
config.action_mailer.delivery_method = :smtp
我尝试了多种变体,但迷路了。我在Windows 7计算机上运行。我正在运行Ruby 1.8.7和Rails 3.0.7
有人可以帮忙吗?
这是我的创建方法:
def create
@user = User.new(params[:user])
if @user.save
UserMailer.registration_confirmation(@user).deliver
sign_in @user
redirect_to @user,:flash => { :success => \"Welcome to the Sample App!\" }
else
@title = \"Sign up\"
render \'new\'
end
end
我的user_mailer.rb
类UserMailer default :from => \"my_user_name@gmail.com\" def registration_confirmation(user) mail(:to => user.email,:subject => \"Thanks for registering\") end end
解决方法
看一下您的服务器。我很确定您可以在日志中看到它实际上是在尝试发送邮件。
问题是Google不信任您的本地IP地址,并且您的邮件也不会发送(甚至不会发送到垃圾邮件目录)。除了使用白名单服务器之外,没有其他方法可以解决此问题。
如果您在生产环境中尝试应用程序,则该方法通常可以正常运行,例如,将应用程序部署到heroku进行测试。
, 尝试在最后放
.deliver
。这为我解决了这个问题:
mail(:to .....).deliver!
, 尝试将身份验证从字符串更改为符号。
ActionMailer::Base.smtp_settings ={
:address => \"smtp.gmail.com\",:port => 587,:domain => \"gmail.com\",:user_name => \"my_user_name@gmail.com\",:password => \"my_password\",:authentication => :plain,:enable_starttls_auto => true
}
, 您应该检查my_user_name@gmail.com是否确实发送了电子邮件。过去,通过Gmail的SMTP服务器发送验证电子邮件时,我们曾遇到此问题,因为批量发送最终根本无法发送。
我建议您登录到my_user_name@gmail.com并确认没有问题并且已发送电子邮件。
如果没有,您可能希望尝试使用诸如“发送网格”之类的服务来发送外发电子邮件。
, 我遇到了同样的问题,我可以看到在控制台中发送了邮件,但是在收件箱中什么也没出现,一件事是您可以将应用程序部署在列入白名单的服务器(例如heroku)上,或者只想进行测试通过本地浏览器,只需在浏览器中启用安全性较低的应用程序,您就应该能够在收件箱中看到该电子邮件
https://myaccount.google.com/lesssecureapps