Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodemailer ECONNREFUSED localhost

I can't find a solution to this error, i'm running locally i already checked if there are services using the ports but there is none

{ Error: connect ECONNREFUSED 127.0.0.1:465
        at Object.exports._errnoException (util.js:1050:11)
        at exports._exceptionWithHostPort (util.js:1073:20)
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1093:14)
      code: 'ECONNECTION',
      errno: 'ECONNREFUSED',
      syscall: 'connect',
      address: '127.0.0.1',
      port: 465,
      command: 'CONN' }

Heres my setting

var transporter = nodemailer.createTransport({
    service: 'smtp.gmail.com',
    port: 465,
    auth: {
      user: process.env.EMAIL,
      pass: process.env.PWD
    }
  });

Also running openssl s_client -starttls smtp -crlf -connect smpt.gmail.com:465 doesn't return anything both on 465 and 587

like image 571
JEEZSUSCRIZE Avatar asked Sep 01 '25 02:09

JEEZSUSCRIZE


1 Answers

u added the host on the service... try this

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport'); // this is important

var transporter = nodemailer.createTransport(smtpTransport({
  service: 'gmail',
  host: 'smtp.gmail.com',
  auth: {
    user: '[email protected]',
    pass: 'realpasswordforaboveaccount'
  }
}));

var mailOptions = {
  from: '[email protected]',
  to: '[email protected]',
  subject: 'Sending Email using Node.js[nodemailer]',
  text: 'That was easy!'
};

transporter.sendMail(mailOptions, function(error, info){
  if (error) {
    console.log(error);
  } else {
    console.log('Email sent: ' + info.response);
  }
});  

then if needed enable "lesssecureapps" by clicking this link

like image 173
Kevin Dias Avatar answered Sep 02 '25 16:09

Kevin Dias