Errno::ECONNREFUSED: Connection refused - connect(2) for action mailer

Solution 1:

In my situation, I encountered similar problems when I was trying to making through a sending-email Rails app tutorial, the Heroku logs kept telling my that

......

Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):

......

After I compared my code with author's code, I got to find out that I had not setup my ActionMailer configurations in the config/environments/production.rb file.

Then I came to realized that I just had my config/environments/development.rb configured for sending-email, but I had not done it for my config/environments/production.rb.

So you may check it when your app's behavior difers between development and production.

Solution 2:

Be sure you have configured your port correctly. I switched from gmail in development (port 587) to sending from my local server in production and was getting this error till I corrected the port to the one my server uses (port 25).

Solution 3:

for production you cant write

config.action_mailer.default_url_options = { :host => "localhost:3000" }

add production url for host, like,

config.action_mailer.default_url_options = { :host => "http://www.yourdomain.com" }