0 votes
1 view
by (12.8k points)

Hi I am working on chef where I have a helper library with the following code

require 'net/smtp'
 module HandlerSendEmail
class Helper
def send_email_on_run_failure(node_name)
  message = "From: Chef <[email protected]>\n"
  message << "To: Grant <[email protected]>\n"
  message << "Subject: Chef run failed\n"
  message << "Date: #{Time.now.rfc2822}\n\n"
  message << "Chef run failed on #{node_name}\n"
  Net::SMTP.start('localhost', 25) do |smtp|
    smtp.send_message message, '[email protected]', '[email protected]'

But when 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

1 Answer

0 votes
by (29.8k points)
edited by
Hi, basically either no SMTP mail server running locally or it is not listening on port 25. For the later, you can check by running the following command

netstat -ntpla | grep 25 - this will return if anything is listening on port 25

if it is the first case then You would need an SMTP server connection on the localhost to resolve your issue. Please try to make that connection and tell me if it worked cheers!
Welcome to Intellipaat Community. Get your technical queries answered by top developers !