简体   繁体   中英

Rails does not send emails on AWS

Im trying to send confirmation emails from my Rails application. In my development environment its working perfectly (in ubuntu). However, when I try to send the emails in my Amazon AWS EC2 instance, it is not working. I get next error log:

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 .

I see a connection refused message, I guess I should config some security credential or open some port... but I have no idea.

UPDATE

To provide some more details. My email service is provided by Zoho, I configured some accounts. I configured two MX record sets in AWS with Route 53. The mail is working, I mean, I can send and receive email from another accounts such as gmail or hotmail to my zoho accounts. And as I said, the email service is working with these accounts in development (which is another ubuntu).

Are you running this application from inside a VPC? If so, verify that your NAT instance's security group allows SMTP inbound/outbound traffic. If it's a classic EC2 instance, do the same in your instance's SG.

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