Rails Mailer Error “Errno::ECONNREFUSED (Connection refused…)” After Installed & Uninstalled Postfix


Please briefly explain why you feel this question should be reported .

Report Cancel

My app on Ruby on Rails has suddenly got an error, shown as below, when it tries to send an email with a Mailer using Gmail.

This problem started after I installed & uninstalled “postfix” on the server (Apache/CentOS) since the installation was too difficult for me. Before that, the Mailer was properly working.


NoticeMailer#newtask_email: processed outbound mail in 2.5ms
I, [2016-08-19T10:55:13.429666 #3782]  INFO -- : 
Sent mail to [email protected] (4.2ms)
D, [2016-08-19T10:55:13.429750 #3782] DEBUG -- : Date: Fri, 19 Aug 2016 10:55:13 +0900
From: [email protected]
To: [email protected]
Message-ID: <defaultdomain.mail>
Subject: test
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit  

I, [2016-08-19T10:55:13.430023 #3782]  INFO -- : Completed 500 Internal Server Error in 17ms (ActiveRecord: 2.0ms)
F, [2016-08-19T10:55:13.431110 #3782] FATAL -- : 
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):
app/controllers/tasks_controller.rb:41:in `create'

Related coding is shown as below:


  config.action_mailer.default_url_options = { host: 'localhost:3000' }
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address: 'smtp.gmail.com',
    port: 587,
    domain: 'gmail.com',
    authentication: :plain,
    user_name: [email protected]',
    password: 'xxxxx'

The coding on should be fine. So, I guess some server settings have been changed due to the installation of postfix.

I installed postfix following the procedure written on the webiste:

And, I uninstalled it by “yum erase postfix”, “yum remove dovecot”, “rm -rf /etc/postfix” and “rm -rf /etc/dovecot”. After that I did “reboot” and “service httpd restart”.

“/etc/sysconfig/iptables” is also same as before.

I have no idea about how to fix this, so could you help me out please…

solved 0
1 Answer 45 views 0

Answer ( 1 )

    January 11, 2017 at 5:30 pm

    Please briefly explain why you feel this answer should be reported .

    Report Cancel

    This problem has been solved by writing same “config.action_mailer.smtp_settings” coding on production.rb as environment.rb.

    It seemed like it had been fine without the coding on production.rb because of default setting before I installed postfix.

    Best answer

Leave an answer


What is the capital of Egypt ? ( Cairo )

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>