Rails不会在AWS上发送电子邮件

时间:2014-05-22 18:48:34

标签: ruby-on-rails email amazon-web-services amazon-ec2

我试图从我的Rails应用程序发送确认电子邮件。在我的开发环境中,它完美地工作(在ubuntu中)。但是,当我尝试在我的Amazon AWS EC2实例中发送电子邮件时,它无法正常工作。我得到下一个错误日志:

BookingRequestEvent.execute
{ 38227580 rufus-scheduler intercepted an error:
  38227580   job:
  38227580     Rufus::Scheduler::EveryJob "60s" {}
  38227580   error:
  38227580     38227580
  38227580     Errno::ECONNREFUSED
  38227580     Connection refused - connect(2)
  38227580       /home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/smtp.rb:541:in `initialize'
  38227580       /home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/smtp.rb:541:in `open'
  38227580       /home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/smtp.rb:541:in `tcp_socket'
  38227580       /home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/smtp.rb:551:in `block in do_start'
  38227580       /home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/timeout.rb:66:in `timeout'
  38227580       /home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/smtp.rb:550:in `do_start'
  38227580       /home/ubuntu/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/smtp.rb:520:in `start'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/mail-2.5.4/lib/mail/message.rb:232:in `block in deliver'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:456:in `block in deliver_mail'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `block in instrument'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.0/lib/active_support/notifications.rb:159:in `instrument'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/actionmailer-4.0.0/lib/action_mailer/base.rb:454:in `deliver_mail'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/mail-2.5.4/lib/mail/message.rb:232:in `deliver'
  38227580       /home/ubuntu/apps/yanpyapi/app/models/notification_manager.rb:6:in `notify'
  38227580       /home/ubuntu/apps/yanpyapi/app/models/events/booking_request_event.rb:22:in `execute'
  38227580       /home/ubuntu/apps/yanpyapi/app/models/secretary.rb:85:in `block in executeEvents'
  38227580       /home/ubuntu/apps/yanpyapi/app/models/secretary.rb:20:in `each'
  38227580       /home/ubuntu/apps/yanpyapi/app/models/secretary.rb:20:in `executeEvents'
  38227580       /home/ubuntu/apps/yanpyapi/config/initializers/task_scheduler.rb:8:in `block in <top (required)>'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:224:in `call'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:224:in `do_trigger'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:269:in `block (3 levels) in start_work_thread'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:272:in `call'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:272:in `block (2 levels) in start_work_thread'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:258:in `loop'
  38227580       /home/ubuntu/.rvm/gems/ruby-2.0.0-p451/gems/rufus-scheduler-3.0.3/lib/rufus/scheduler/jobs.rb:258:in `block in start_work_thread'
} 38227580 .

我看到连接被拒绝的消息,我想我应该配置一些安全凭证或打开一些端口......但我不知道。

更新

提供更多详情。我的电子邮件服务由Zoho提供,我配置了一些帐户。我在AWS中使用Route 53配置了两个MX记录集。邮件正在运行,我的意思是,我可以从其他帐户(例如gmail或hotmail)向我的zoho帐户发送和接收电子邮件。正如我所说,电子邮件服务正在开发这些帐户(这是另一个ubuntu)。

1 个答案:

答案 0 :(得分:1)

您是否在VPC内部运行此应用程序?如果是,请验证您的NAT实例的安全组是否允许SMTP入站/出站流量。如果它是经典的EC2实例,请在实例的SG中执行相同操作。