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

时间:2011-03-31 00:25:08

标签: ruby-on-rails-3 email gmail actionmailer

我一直试图解决这个问题太多时间了。我查看了Railscast,官方Rails指南,很多博客文章,但都没有帮助。

我正在尝试使用ActionMailer 2.2.5通过我的Google Apps帐户从我的Rails 3应用发送电子邮件。我验证了用户名和密码。我可以在控制台上看到要发送的消息。我从控制器中的传递调用中获得了 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 => 'user@test.com',
  :password => 'mypass'
}

# app/mailers/test_mailer.rb
class PostMailer < ActionMailer::Base
  default :from => "no-reply@test.com"

 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

1 个答案:

答案 0 :(得分:2)

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

:port => 587

同样在我的代码中,我在actionmailer config之前有以下行:

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

您是否有任何理由使用旧版本的actionmailer和rails 3?我建议使用与你的rails版本相对应的actionmailer版本。

希望这有帮助。