0

Problem: Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25): on cloudcontrol server.

Environment smtp settings:

   config.action_mailer.smtp_settings = {
    address: "smtp.mandrillapp.com",
    port: 587,
    enable_starttls_auto: true, 
    user_name: ENV["MANDRILL_USER"],
    password: ENV["MANDRILL_PASSWORD"],
    authentication: 'login',
    domain: 'domain.example'
}

When checking the Project::Application.config.action_mailer.smtp_settings on server, receive this and it is correct:

{:address=>"smtp.mandrillapp.com", :port=>587, :enable_starttls_auto=>true, :user_name=>"correct_user", :password=>"correct_password", :authentication=>"login"}

But still cat't send email becouse of problem described above. Mailer somehow skips this settings and uses :address=>"localhost", :port=>25 If I use Net::SMTP directly with indicating the address and port on the server console it sends mail properly:

Net::SMTP.start('smtp.mandrillapp.com', 587, 'some_domain', ENV["MANDRILL_USER"], ENV["MANDRILL_PASSWORD"], :login) do |smtp|
 smtp.send_message msgstr, 
 'user@mail.com',
 'user1@mail.com'
end

=> #<Net::SMTP::Response:0x007f1a6e763998 @status="250", @string="250 2.0.0 Ok: queued as B768D480191\n">

Can anyone help to set smtp settings on cloudcontrol? Or have I missed somethig about the cloudcontrol platform?

It is actually staging server...

Project::Application.configure do

 config.cache_classes = true
 config.action_controller.default_url_options = {:host => "staging_server_host"}
 config.action_mailer.default_url_options = {:host => 'staging_server_host'}
 config.consider_all_requests_local = false

 config.action_controller.perform_caching = true
 config.serve_static_assets = false
 config.action_mailer.delivery_method = :smtp

 config.action_mailer.perform_deliveries = true
 config.assets.compress = true
 config.assets.compile = true

 config.assets.digest = true
 config.log_level = :debug
 config.action_controller.asset_host = "staging_server_host"

 config.action_mailer.raise_delivery_errors = true
 config.i18n.fallbacks = true
 config.active_support.deprecation = :notify

 config.after_initialize do
   config.action_mailer.smtp_settings = {
       address: "smtp.mandrillapp.com",
       port: 587, # ports 587 and 2525 are also supported with STARTTLS
       enable_starttls_auto: true, # detects and uses STARTTLS
       user_name: ENV["MANDRILL_USER"],
       password: ENV["MANDRILL_PASSWORD"], # SMTP password is any valid mandrill API key
       authentication: 'login', # Mandrill supports 'plain' or 'login'
       domain: 'cloudcontrolapp.com', # your domain to identify your server when connecting
   }
 end
end

EDITED: Here is Procfile I found on server:

web: bundle exec thin start -R config.ru -e $RAILS_ENV -p $PORT
rake: bundle exec rake
worker: bundle exec rake jobs:work
console: bundle exec rails console
Sergii Brytiuk
  • 345
  • 1
  • 12
  • Can you provide full production config file - config/environments/production.rb? – mkorszun Nov 13 '14 at 16:11
  • @mkorszun, thank you. I have added config file. Could you please ispect? – Sergii Brytiuk Nov 13 '14 at 18:28
  • Is it possible that you are using a non production configuration while deploying to cloudControl? Config file looks ok - do you explicitly export RAILS_ENV in your Procfile? – mkorszun Nov 14 '14 at 14:34
  • @mkorszun, this is staging config (production config is identical) file and cloudControl RAILS_ENV is set to `RAILS_ENV: staging` by default. If I change anything else in the config file and redeploy staging app running accordingly to those changes. The only thing app skips while running on server is smtp_settings. – Sergii Brytiuk Nov 14 '14 at 14:57
  • Do not forget to set `RACK_ENV` as `staging` too. – Fernando Á. Nov 14 '14 at 16:49
  • @FernandoÁ., thank you, just set RACK_ENV as staging. But still no effect. It seems like app is runnin in some parallel environment. I do not understand how server runs on planform. And I have added Procfile inhoud. – Sergii Brytiuk Nov 14 '14 at 19:06

2 Answers2

1

The problem was here in staging.rb:

config.after_initialize do
  #adding smtp settings in this block was invisible (or too late) for staging.rb
end

Possibly it will help someone who is not familiar with rails initializing process. I am not really:)

Sergii Brytiuk
  • 345
  • 1
  • 12
0

For anyone else encountering this issue, Sergii is correct in his diagnosis, but there is a workaround. After you set the smtp_settings on config.action_mailer, copy them to ActionMailer::Base.smtp_settings:

ActionMailer::Base.smtp_settings = config.action_mailer.smtp_settings
ajselvig
  • 688
  • 1
  • 5
  • 12