亚马逊网络服务 SES smtp 超时
Amazon Web Services SES smtp timeout
我在我的 Rails 4 Web 应用程序中使用 AWS SES 向客户发送通知电子邮件。发送电子邮件时,我发现很多次由于 SES 中的 SMTP 超时错误导致电子邮件发送失败。最后,经过一些重试,电子邮件已发送,但我不希望这些重试。
我无需更改应用程序中的任何内容即可发送电子邮件,重试几次后即可。
我附上错误日志:
{ 70220114991960 rufus-scheduler intercepted an error:
70220114991960 job:
70220114991960 Rufus::Scheduler::EveryJob "60s" {}
70220114991960 error:
70219770058060
70219770058060 Net::OpenTimeout
70219770058060 execution expired
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `initialize'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `open'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `tcp_socket'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:551:in `block in do_start'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `call'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `timeout'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:550:in `do_start'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:520:in `start'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:232:in `block in deliver'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:456:in `block in deliver_mail'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `block in instrument'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `instrument'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:454:in `deliver_mail'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:232:in `deliver'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/notification_manager.rb:40:in `notify'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/events/boat_provider_payment_event.rb:104:in `execute'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/secretary.rb:87:in `block in executeEvents'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/secretary.rb:20:in `each'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/secretary.rb:20:in `executeEvents'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/config/initializers/task_scheduler.rb:9:in `block in <top (required)>'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:224:in `call'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:224:in `do_trigger'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:269:in `block (3 levels) in start_work_thread'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:272:in `call'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:272:in `block (2 levels) in start_work_thread'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:258:in `loop'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:258:in `block in start_work_thread'
} 70219770058060 .
解决方法是设置一个本地 smtp 服务器,您的 rails 应用将其用作 smtp 服务器。本地 smtp 服务器将中继到 SES。如果通过 ses 中继失败,像 postfix 这样的本地 smtp 服务器将自动重试,因此您的 rails 代码只需要将邮件排队一次。
看起来它只是通过更改我的 Rails 应用程序中的 SMTP 端口配置来工作。我将端口更改为 587。
我在我的 Rails 4 Web 应用程序中使用 AWS SES 向客户发送通知电子邮件。发送电子邮件时,我发现很多次由于 SES 中的 SMTP 超时错误导致电子邮件发送失败。最后,经过一些重试,电子邮件已发送,但我不希望这些重试。
我无需更改应用程序中的任何内容即可发送电子邮件,重试几次后即可。
我附上错误日志:
{ 70220114991960 rufus-scheduler intercepted an error:
70220114991960 job:
70220114991960 Rufus::Scheduler::EveryJob "60s" {}
70220114991960 error:
70219770058060
70219770058060 Net::OpenTimeout
70219770058060 execution expired
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `initialize'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `open'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:541:in `tcp_socket'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:551:in `block in do_start'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `call'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `timeout'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:550:in `do_start'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/2.1.0/net/smtp.rb:520:in `start'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:232:in `block in deliver'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:456:in `block in deliver_mail'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `block in instrument'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `instrument'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:454:in `deliver_mail'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/mail-2.5.4/lib/mail/message.rb:232:in `deliver'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/notification_manager.rb:40:in `notify'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/events/boat_provider_payment_event.rb:104:in `execute'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/secretary.rb:87:in `block in executeEvents'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/secretary.rb:20:in `each'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/app/models/secretary.rb:20:in `executeEvents'
70219770058060 /home/ubuntu/env/test/www/yanpyapi-test/config/initializers/task_scheduler.rb:9:in `block in <top (required)>'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:224:in `call'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:224:in `do_trigger'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:269:in `block (3 levels) in start_work_thread'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:272:in `call'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:272:in `block (2 levels) in start_work_thread'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:258:in `loop'
70219770058060 /home/ubuntu/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:258:in `block in start_work_thread'
} 70219770058060 .
解决方法是设置一个本地 smtp 服务器,您的 rails 应用将其用作 smtp 服务器。本地 smtp 服务器将中继到 SES。如果通过 ses 中继失败,像 postfix 这样的本地 smtp 服务器将自动重试,因此您的 rails 代码只需要将邮件排队一次。
看起来它只是通过更改我的 Rails 应用程序中的 SMTP 端口配置来工作。我将端口更改为 587。