1

服务器指出电子邮件已发送到正确的地址,但我没有在收件箱中收到邮件。

我的 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 < ActionMailer::Base

default :from => "my_user_name@gmail.com"

def registration_confirmation(user)
mail(:to => user.email, :subject => "Thanks for registering")

end
end
4

5 回答 5

5

看看你的服务器。我很确定您可以在日志中看到它实际上正在尝试发送邮件。

问题是 Google 不信任您的本地 IP 地址,并且您的邮件不会送达(甚至不会送达垃圾邮件目录)。没有办法解决这个问题,只能使用列入白名单的服务器。

如果您在生产环境中尝试您的应用程序,这应该可以正常工作,例如将您的应用程序部署到 heroku 进行测试。

于 2011-06-14T17:28:24.667 回答
2

尝试.deliver在最后插入。这为我解决了这个问题:

mail(:to .....).deliver!
于 2013-12-23T06:12:01.480 回答
0

您应该检查my_user_name@gmail.com是否实际发送了电子邮件。我们过去在通过 Gmail 的 SMTP 服务器发送验证电子邮件时遇到过这个问题,因为批量发送最终根本不发送。

我建议您登录 my_user_name@gmail.com 并确认没有问题并且电子邮件已发送。

如果没有,您可能需要尝试使用Send Grid 之类的服务来发送外发电子邮件。

于 2011-06-14T17:19:46.870 回答
0

尝试将身份验证从字符串更改为符号。

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
}
于 2011-06-14T16:55:05.177 回答
0

我遇到了同样的问题,我能够看到在我的控制台中发送了邮件,但在收件箱中没有出现任何内容,一件事是您可以将您的应用程序部署在像 heroku 这样的白名单服务器上,或者如果您只想查看以进行测试通过您的本地只需在浏览器中启用安全性较低的应用程序,您应该能够在收件箱中看到该电子邮件 https://myaccount.google.com/lesssecureapps

于 2019-02-03T15:18:46.803 回答