Rails 3 ActionMailer Google Apps:超时::错误
我已经花了太多小时试图解决这个问题。我查看了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试两件事。首先,将端口设置为数字而不是字符串:
另外,在我的代码中,我在actionmailer配置之前有以下行:
您在rails 3中使用旧版本的actionmailer有什么原因吗?我建议使用与您的 Rails 版本相对应的 Actionmailer 版本。
希望这有帮助。
I would try two things. First off make port a number instead of a string:
Also in my code I have the following line before the actionmailer config:
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.