• Home
  • Q&A
  • rails3 can't send smtp email in production mode
 
2
0
0

rails3 can't send smtp email in production mode

KentTuckyviaStackOverflow
February 26, 2013
2 score
2 answers

According to my problem I posted here: mailer error in production only I decided to create a small scaffold app to find a solution.

The problem: I can't send (newsletter)email with smtp in production, but it works perfectly in development.

You can find the app in my github repository.

I just created a contact_messages scaffold and a simple mailer.

The error log after clicking on the submit button to receive email:

Started POST "/contact_messages" for 194.XXX.XX.XXX at 2013-02-26 19:43:59 +0000
Processing by ContactMessagesController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"xx0nxxJ2xwxxJavvZ278EUy2TABjD9CixxNcxDqwg=",
"contact_message"=>{"name"=>"test", "email"=>"test@testemail.com", "message"=>"test1"}, "commit"=>"Create Contact message"}
Rendered contact_mailer/confirmation.text.erb (0.3ms)

Sent mail to test@testemail.com (38ms)
Completed 500 Internal Server Error in 100ms

Errno::ECONNREFUSED (Connection refused - connect(2)):
  app/controllers/contact_messages_controller.rb:46:in `create'

The emails get saved, they are listed in the index. So the database should work fine.

I'm using Ubuntu 12.04, Apache, Phusion Passenger, SMTP with Gmail Account. Could this probably be a server issue, or am I doing something wrong in the app?

I'm using fail2ban and denyhost. Could these tools block smtp?

Any help will be appreciated, thanks!

Answers

0 score

I solved my problem with a change to a new passwort (api-key) from mandrill. Still don't know what the problem was, because with the old one it worked in development mode...

The working setting:

YourApp::Application.configure do
  config.action_mailer.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 587,
    :enable_starttls_auto => true,
    :user_name => "MANDRILL_USERNAME",
    :password  => "MANDRILL_PASSWORD", # SMTP password is any valid API key
    :authentication => 'login'
  }
answered February 27, 2013
1 score

By default, Rails sends email by connecting to the target SMTP server. Try using sendmail instead. Add this in your config/initializers/production.rb:

config.action_mailer.delivery_method = :sendmail
answered February 27, 2013
Discussion

-