我在 Ubuntu 12.04 TLS VPS 上使用 Ruby MRI 2.0.0 和 Rails 3.2.12 并尝试在我的应用程序中设置电子邮件通知。几天前它工作正常,但现在不行了。我的虚拟主机是 OVH。
我的 SMTP 设置:
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => 'sender@gmail.com',
:password => 'secret',
:authentication => 'plain',
:enable_starttls_auto => true
}
使用RAILS_ENV=production rails console
:
class MyMailer < ActionMailer::Base
def test_email
sender = "sender@gmail.com"
receiver = "receiver@example.com"
mail from: sender, to: receiver, subject: "Hello!", body: "World!!"
end
end
=> nil
MyMailer.test_email.deliver
输出:
Net::OpenTimeout: execution expired
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:540:in `initialize'
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:540:in `open'
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:540:in `tcp_socket'
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:550:in `block in do_start'
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:549:in `do_start'
from ~/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/net/smtp.rb:519:in `start'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/mail-2.4.4/lib/mail/network/delivery_methods/smtp.rb:144:in `deliver!'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/mail-2.4.4/lib/mail/message.rb:2034:in `do_delivery'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/mail-2.4.4/lib/mail/message.rb:229:in `block in deliver'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/actionmailer-3.2.12/lib/action_mailer/base.rb:415:in `block in deliver_mail'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `block in instrument'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `instrument'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/actionmailer-3.2.12/lib/action_mailer/base.rb:413:in `deliver_mail'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/mail-2.4.4/lib/mail/message.rb:229:in `deliver'
from (irb):28
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from ~/.rvm/gems/ruby-2.0.0-p0@mygemset/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'2.0.0p0 :029 >
我尝试了以下方法:
exception_notification
几天前,宝石已添加到设置中。我试图评论它的行Gemfile
以及它的匹配配置,然后运行bundle install
. 重新启动服务器后,即使我删除并重新创建 gemset,问题仍然存在。- 在虚拟机上测试它(与 VPS 完全相同的设置,包括 iptables 规则):有效
- 禁用 iptables 规则:不起作用
- 使用 openssl 从 VPS 手动连接到 Gmail:工作(所以这不是防火墙问题 - 请参见此处:通过命令行连接到 smtp.gmail.com);
- 在 Gmail 帐户选项中启用 IMAP(已禁用):不起作用
- 使用其他 Gmail 帐户:不起作用
- 用 Ruby 1.9.3 替换 Ruby 2.0.0
- 升级到 Rails 3.2.13
有人对如何解决此问题有可能的线索吗?
谢谢!