简体   繁体   中英

Amazon Web Services SES smtp timeout

I´m using AWS SES to send notification emails to customers in my Rails 4 web application. When an email is sent, I have realized that many times the email sending fails due to an SMTP Timeout error in SES. Finally, after some retries the email is sent, but I don´t want these retries.

I don´t have to change anything in my application so that the email can be sent, it works after some retries.

I attach the error log:

{ 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 .

It looks like it´s working just by changing the SMTP port configuration in my Rails application. I changed the port to 587.

An workaround would be to setup a local smtp server which your rails app uses as smtp server. The local smtp server will relay to SES. Local smtp servers like postfix will automatically retry if relaying through ses fails, so your rails code will need to queue the mail only once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM