Search code examples
rubyruby-on-rails-3.1actionmailer

ActionMailer not sending mail in Rails 3.1.1


I'm getting error in ActionMailer when my worker is trying to send email

Errno::ECONNREFUSED
    Connection refused - connect(2)

/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `initialize'
/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `open'
/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:546:in `tcp_socket'
/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:555:in `block in do_start'
/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:58:in `timeout'
/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/timeout.rb:89:in `timeout'
/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:555:in `do_start'
/Users/bhushan/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/smtp.rb:525:in `start'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.3.0/lib/mail/network/delivery_methods/smtp.rb:128:in `deliver!'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.3.0/lib/mail/message.rb:1989:in `do_delivery'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.3.0/lib/mail/message.rb:230:in `block in deliver'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.1/lib/action_mailer/base.rb:432:in `block in deliver_mail'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/notifications.rb:53:in `block in instrument'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/notifications.rb:53:in `instrument'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.1/lib/action_mailer/base.rb:430:in `deliver_mail'
/Users/bhushan/.rvm/gems/ruby-1.9.2-p290/gems/mail-2.3.0/lib/mail/message.rb:230:in `deliver'
/Users/bhushan/betterlabs_projects/companyplus_beta/cp_frontend/app/workers/set_crawling.rb:29:in `perform'

I have a file setup_mail.rb in initializers which has smtp settings

 ActionMailer::Base.smtp_settings = {
 address: "smtp.gmail.com",
 port: 587,
 domain: 'betterlabs.net',  
 user_name: '[email protected]',
 password:
 authentication: 'plain',
 enable_starttls_auto: true
 }

and my mailer method

   def send_email(email)
begin
# attachments['result.csv'] = File.read(file)
 mail(to: "[email protected]", subject: "hey")
 puts "====Mail Sent===="
 rescue Exception=>e
 puts e.inspect
 end
end

development.rb

  config.action_mailer.delivery_method = :smtp

Any insight on what could be wrong? Thanks.


Solution

  • check the :from key that you have defined in the start of the ActionMailer class