Rails 3 ActionMailer Google Apps:超时::错误

发布于 2024-10-29 05:02:14 字数 1488 浏览 5 评论 0原文

我已经花了太多小时试图解决这个问题。我查看了 Railscast、官方 Rails 指南、大量博客文章,但没有一个有帮助。

我正在尝试通过我的 Google Apps 帐户使用 ActionMailer 2.2.5 从我的 Rails 3 应用程序发送电子邮件。我验证了用户名和密码。我可以在控制台上看到要发送的消息。我从控制器中的 deliver 调用中收到 Timeout::Error

有人可以阐明这一点吗?

这是代码:

# config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :enable_starttls_auto => true,
  :tls => true,
  :address => 'smtp.gmail.com',
  :port => "587",
  :authentication => :plain,                                                                                                                     
  :domain => 'test.com',
  :user_name => '[email protected]',
  :password => 'mypass'
}

# app/mailers/test_mailer.rb
class PostMailer < ActionMailer::Base
  default :from => "[email protected]"

 def activate_email( post )
   @post = post
   mail( :to => post.email,
         :subject => "Testing" )
   end
 end

# app/controllers/test_controller.rb
class TestController < ApplicationController
  def create
    @post = Post.new( params[:post] )
    TestMailer.activate_email( @post ).deliver
  end
end

I've been trying to fix this for way too many hours. I looked at Railscast, official Rails Guides, lots of blog posts and none of them help.

I'm trying to send email from my Rails 3 app using ActionMailer 2.2.5 via my Google Apps account. I verified the username and password. I can see on the console the message to be sent. I'm getting a Timeout::Error from the deliver call in my controller.

Can someone shed any light on this?

Here's the code:

# config/environments/development.rb
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :enable_starttls_auto => true,
  :tls => true,
  :address => 'smtp.gmail.com',
  :port => "587",
  :authentication => :plain,                                                                                                                     
  :domain => 'test.com',
  :user_name => '[email protected]',
  :password => 'mypass'
}

# app/mailers/test_mailer.rb
class PostMailer < ActionMailer::Base
  default :from => "[email protected]"

 def activate_email( post )
   @post = post
   mail( :to => post.email,
         :subject => "Testing" )
   end
 end

# app/controllers/test_controller.rb
class TestController < ApplicationController
  def create
    @post = Post.new( params[:post] )
    TestMailer.activate_email( @post ).deliver
  end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒废 2024-11-05 05:02:14

我会尝试两件事。首先,将端口设置为数字而不是字符串:

:port => 587

另外,在我的代码中,我在actionmailer配置之前有以下行:

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)

您在rails 3中使用旧版本的actionmailer有什么原因吗?我建议使用与您的 Rails 版本相对应的 Actionmailer 版本。

希望这有帮助。

I would try two things. First off make port a number instead of a string:

:port => 587

Also in my code I have the following line before the actionmailer config:

Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)

Is there any reason that you are using an old version of actionmailer with rails 3? I would recommend using the version of actionmailer that corresponds to your rails version.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文