0

I'm trying sending emails using node mailer but I'm getting the error Error: connect ECONNREFUSED 127.0.0.1:587

at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16) {

errno: -4078,

code: 'ESOCKET',

syscall: 'connect',

address: '127.0.0.1',

port: 587,

command: 'CONN'

}

var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport({

  service: 'smtp.outlook.com',

  secure: false, 

  debug: true,

  secureConnection: false,

  port: 587,

  auth: {

    user: 'myemail@outlook.com',

    pass: 'pass'

  }  ,

  tls: {

      rejectUnauthorized: true,
     

  }
});

var mailOptions = {

  from: 'myemail@outlook.com',

  to: 'myemail@outlook.com',

  subject: 'Sending Email using Node.js',

  text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){

  if (error) {

    console.log(error);

  } 

else {

    console.log('Email sent: ' + info.response);

  }

});
Ali Nawaz
  • 43
  • 1
  • 7
  • 1
    What's the version of the package? Now you're supposed to provide host address via `host` param, not `service` param it seems. – raina77ow Jun 01 '22 at 12:58
  • A look into the documentation would tell you in 3 secs where your problem is: https://nodemailer.com/smtp/well-known/ Otherwise dump the "service" and specify host/port manually. – Marc Jun 01 '22 at 13:15
  • Answering your question in the deleted answer: https://stackoverflow.com/questions/46742402/error-self-signed-certificate-in-certificate-chain-nodejs-nodemailer-express – raina77ow Jun 01 '22 at 13:51
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 01 '22 at 19:17
  • Had the same error. After removing 'service' parameter and adding correct hostname for 'host' parameter all worked perfectly. – Elmatsidis Paul Sep 14 '22 at 21:45

0 Answers0