Rails Cast:ActionMailer 电子邮件未发送到收件箱
服务器表明电子邮件已发送到正确的地址,但我的收件箱中没有收到该消息。
我的 Setup_mail.rb 文件
ActionMailer::Base.smtp_settings ={
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "[email protected]",
: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 类 < ActionMailer::基础
default :from => "[email protected]"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Thanks for registering")
end
end
The server states that the email was sent to the correct address but I am not getting the message in my inbox.
My Setup_mail.rb file
ActionMailer::Base.smtp_settings ={
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "[email protected]",
:password => "my_password",
:authentication => "Plain",
:enable_starttls_auto => true
}
My development.rb
file is:
# 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
My test.rb
file is:
config.action_mailer.delivery_method = :smtp
I have tried multiple variations and am lost. I am running on a Windows 7 machine. I am running Ruby 1.8.7 and Rails 3.0.7
Can anyone help?
Here is my create method:
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
My user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def registration_confirmation(user)
mail(:to => user.email, :subject => "Thanks for registering")
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看看你的服务器。我很确定您可以在日志中看到它实际上正在尝试发送邮件。
问题是 Google 不信任您的本地 IP 地址,因此您的邮件不会被发送(甚至不会发送到垃圾邮件目录)。除了使用列入白名单的服务器之外,没有其他方法可以解决此问题。
如果您在生产中尝试您的应用程序,这通常应该可以工作,例如将您的应用程序部署到 heroku 来测试它。
Take a look at your server. I'm pretty sure that you can see in your logs that it's actually trying to send the mail.
The problem is that Google doesn't trust your local IP address and your mails won't get delivered (not even to the spam directory). There is no way to work around this but using a whitelisted server.
If you try your app in production this should normally work, for example deploy your app to heroku to test it.
尝试在最后放入
.deliver
。这为我解决了这个问题:Try putting in
.deliver
at the end. That fixed this issue for me:尝试将身份验证从字符串更改为符号。
Try changing the authentication from a string to a symbol.
您应该检查[电子邮件受保护] 是否已实际上发送了电子邮件。过去,我们在通过 Gmail 的 SMTP 服务器发送验证电子邮件时遇到过此问题,因为批量发送最终根本无法发送。
我建议您登录[email protected]并验证是否没有问题并且电子邮件已发送。
如果没有,您可能需要尝试使用 Send Grid 等服务来发送外发电子邮件。
You should check that [email protected] has actually sent the email. We have had issues with this in the past when sending verification emails out through Gmail's SMTP server, since sending in bulk end up not sending at all.
I suggest you log into [email protected] and verify that there are no problems and that the emails are sent.
If not, you may want try a service like Send Grid to send outgoing emails.
我遇到了同样的问题,我可以在我的控制台中看到邮件已发送,但收件箱中没有出现任何内容,一件事是您可以将应用程序部署在像heroku这样的白名单服务器上,或者如果您只想查看以进行测试目的通过本地,只需在浏览器中启用不太安全的应用程序,您应该能够在收件箱中看到该电子邮件
https://myaccount.google.com/lesssecureapps
I had this same issue, I was able to see that in my console mail was sent but in inbox nothing was appearing, one thing is that you can deploy your app on whitelisted server like heroku, or if you want to see just for testing purpose through your local just enable less secure apps in your browser and you should be able to see that email in your inbox
https://myaccount.google.com/lesssecureapps