Connection refused - connect(2) for “localhost” port 25 chef devops

I am working on chef(devops) where I have a helper library with the following code in it

require 'net/smtp'

module HandlerSendEmail
class Helper

def send_email_on_run_failure(node_name)

  message = "From: Chef <>\n"
  message << "To: Grant <>\n"
  message << "Subject: Chef run failed\n"
  message << "Date: #{}\n\n"
  message << "Chef run failed on #{node_name}\n"
  Net::SMTP.start('localhost', 25) do |smtp|
    smtp.send_message message, '', ''

end end

But whhen I run the recipe I get

Chef Client failed. 0 resources updated in 02 seconds
[2017-10-30T05:19:38+00:00] ERROR: Connection refused - connect(2) for "localhost" port 25
[2017-10-30T05:19:38+00:00] ERROR: Connection refused - connect(2) for "localhost" port 25
I tried changing port to 90 and some other options I keep getting same error.There are some solution available on few posts on stackoverflow already but all of them are talking about some other .rb files which is not present on my dev environment.

Connection refused - connect(2) Ruby on Rails Mail Setup Errno::ECONNREFUSED: Connection refused - connect(2) for action mailer| DevOps

Sounds like there is no SMTP mail server running locally, or at least it is not listening on port 25. Do you have a postfix/exim/sendmail running on localhost? You can check, for example with netstat -ntpla | grep 25 if anything is listening on port 25.

1 Like

I have same issue...there's nothing running on port 25 on my there a way sample recipe to configure my enterprise SMTP server

class Net::SMTP w/ examples for external SMTP servers...