简体   繁体   中英

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 <chef@chef.io>\n"
  message << "To: Grant <xyz@test.com>\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, 'chef@chef.io', 'xyz@test.com'
  end
end

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

You would need to have an actual SMTP server listening on localhost and I'm guessing you don't have one. Without more information it's hard to say though. If you don't want run your own relay server, you can find instructions all over the internet for setting up outbound SMTP via GMail, Amazon SES, Sparkpost, Sendgrid, and may more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM