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

倾然丶 夕夏残阳落幕 提交于 2019-11-27 21:47:47

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.

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).

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" }

My problem is not identical to this question, but I feel many would found this thread via google.

If you use external SMTP service like sendgrid and has set up ActionMailer accordingly, yet it still gives this error:

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

You may be passing config hash with String key, which are ignored. Keys must be symbols!

This may happen if it is de-serialized, what I did is to ensure keys are symbols:

config.action_mailer.smtp_settings = get_smtp_setting.symbolize_keys

There is another reason for this error:

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

It should be looked at SENDMAIL service on your server:

  • Is SENDMAIL installed?
  • Is SENDMAIL running?

I had this error due to the stopped SENDMAIL.

Good luck!

Ken Prince

I just tracked down a similar problem while trying to deploy wordpress with Capistrano.

cap aborted! Errno::ECONNREFUSED: Connection refused - connect(2) for "{my-ip-address}" port {my-ssh-port}

I would also get this similar error:

Tasks: TOP => git:create_release (See full trace by running task with --trace) The deploy has failed with an error: #<Errno::ECONNREFUSED: Connection refused - connect(2) for "my-ip-address" port {my-port}>

It turns out it was an issue with concurrent SSH sessions as my server runs Fail2Ban. To solve that I simply did the following:

  1. Edit the jail that contains SSH configurations

    $ sudo nano /etc/fail2ban/jail.local

  2. look for [SSH] and set enabled = false

  3. then find [ssh-ddos] and set enabled = false

  4. Remember to restart Fail2Ban after your changes and open-ssh (if thats what your using)

$ sudo service fail2ban reload

$ sudo /etc/init.d/ssh reload

Its worth noting that the connection would be refused at different steps (tasks) in the deployment. For example after a reboot and a quick bundle exec cap production deploy:check everything appeared fine. Then I tried to deploy and received the same error, but during the execution of a different task. I also use UFW which I disabled and reenabled without issues. UFW was not the cause of the above problem.

I had a similar problem after I solved this. It was an issue with the current directory permissions. That's over here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!