RSync
RSync

Reputation: 121

Rails - Can't send email on production using mailgun

I have an app deployed in heroku, mails are sent successfully only in development but not in production. I'm using mailgun. Here are the error results:

Exception
Net::OpenTimeout
Error
execution expired
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:541:in `initialize'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:541:in `open'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:541:in `tcp_socket'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:551:in `block in do_start'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/timeout.rb:98:in `call'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/timeout.rb:98:in `timeout'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:550:in `do_start'
/app/vendor/ruby-2.2.6/lib/ruby/2.2.0/net/smtp.rb:520:in `start'
/app/vendor/bundle/ruby/2.2.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp.rb:113:in `deliver!'
/app/vendor/bundle/ruby/2.2.0/gems/mail-2.6.4/lib/mail/message.rb:253:in `deliver!'
/app/vendor/bundle/ruby/2.2.0/gems/actionmailer-4.2.5/lib/action_mailer/message_delivery.rb:77:in `deliver_now!'
/app/vendor/bundle/ruby/2.2.0/gems/actionmailer-4.2.5/lib/action_mailer/delivery_job.rb:10:in `perform'
/app/vendor/bundle/ruby/2.2.0/gems/activejob-4.2.5/lib/active_job/execution.rb:32:in `block in perform_now'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:343:in `call'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:343:in `block (2 levels) in simple'
/app/vendor/bundle/ruby/2.2.0/gems/i18n-0.8.1/lib/i18n.rb:257:in `with_locale'

and my config/environments/production.rb code

config.action_mailer.delivery_method = :smtp
    ActionMailer::Base.smtp_settings = 
   {

     :address              => 'mailgun.org',
     :port                 => ENV['MAILGUN_SMTP_PORT'],
     :domain               => ENV['MY_DOMAIN'],
     :user_name            => ENV['MAILGUN_SMTP_LOGIN'],
     :password             => ENV['MAILGUN_SMTP_PASSWORD'],
     :authentication       => 'plain'
   }

  config.action_mailer.default_url_options = { :host => 'https://myapp.herokuapp.com/' }
  config.action_mailer.asset_host = 'https://myapp.herokuapp.com/'
  config.action_controller.asset_host = 'https://myapp.herokuapp.com/'

Upvotes: 0

Views: 806

Answers (1)

RSync
RSync

Reputation: 121

Alright, I didn't notice that I am using just 'mailgun.org' instead of 'smtp.mailgun.org' for the address. I changed the address value to ENV['MAILGUN_SMTP_SERVER'] and then it's working properly in production.

Upvotes: 1

Related Questions