mav*_*tic 35 smtp ruby-on-rails actionmailer exception-notification
我在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
}
Run Code Online (Sandbox Code Playgroud)
使用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
Run Code Online (Sandbox Code Playgroud)
输出:
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 >
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
exception_notification几天前,宝石被添加到设置中.我试着评论它的线Gemfile以及它的匹配配置,然后运行bundle install.重新启动服务器后,即使我删除并重新创建gemset,问题仍然存在.有人可能有关于如何解决此问题的线索吗?
谢谢!
Zip*_*pie 17
我可能有同样的问题,我的生产应用程序没有发送邮件,虽然开发中的一切都运行良好.我也得到了"Net :: OpenTimeout"错误.
我的问题是我在生产中使用了Google服务器,它在出站连接上阻止了端口25,465和587.
由于我使用Mandrill发送邮件,我能够将连接端口从587切换到2525,现在一切正常.
Dan*_*iro 15
首先,与Telnet直接连接:
telnet smtp-relay.sendinblue.com 587
Trying 94.143.17.4...
Run Code Online (Sandbox Code Playgroud)
这是基本连接故障排除,适用于任何提供商或端口.用您的实际主机名/端口替换SendBlue和587端口.
如果您收到此错误:
telnet: Unable to connect to remote host: Connection timed out
Run Code Online (Sandbox Code Playgroud)
那么,问题不在于Rails.
在上面的示例中,问题出在端口号中.sendinblue或mandrill等服务(我相信gmail也不再支持587端口)."2525"是新的"587".
如果你在telnet上超时,请检查:
Dar*_*rme 13
这里还有一个临时修复,可能会在等待您的托管服务提供商解决问题时派上用场:
将以下行添加到/etc/sysctl.conf:
#disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
Run Code Online (Sandbox Code Playgroud)
现在,应用程序可以再次发送电子邮件.
您始终可以知道是否已启用IPv6呼叫
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
Run Code Online (Sandbox Code Playgroud)
从终端.两个可能的答案:0 =>启用IPv6; 1 => IPv6已禁用.
来自:https://serverfault.com/questions/512744/timeout-error-in-all-my-apps-for-every-call-to-smtp-servers
您可以将Ubuntu配置为首选IPv4 over IPv6.这样,您就可以发送电子邮件并访问仅限IPv6的站点.编辑/etc/gai.conf并取消注释以下行:
precedence ::ffff:0:0/96 100
Run Code Online (Sandbox Code Playgroud)