0

Nodemailer has suddenly throwing up below error when sending email on server code. However when run as a standalone file it works! No clue on why it is going wrong - I have checked many similar questions in stackoverflow - none is helping.

There has been no code change from my end and it is as below

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

Below is the sample code

let mailer = {
  from: 'Company',
  options: {
    service: 'gmail',
    auth: {
      user: 'example@gmail.com',
      pass: 'secret'
    }
  }
}

let email = nodemailer.createTransport(mailer.options);


let mailOptions = {};

mailOptions['to'] = 'example@gmail.com';
mailOptions['from'] = mailer.from;
mailOptions['subject'] = 'basic';
mailOptions['html'] = 'hello world';


email.sendMail(mailOptions, err => {
  if (!err) {
    console.log('sent email succesfully');
  } else {
    console.log('error sending email', err);
  }

  cbk(err, null);

});
npr
  • 4,325
  • 4
  • 20
  • 30
  • [Possibly another `service` `listening`.](https://stackoverflow.com/a/35917623/2569323) – deEr. May 12 '18 at 09:39
  • I checked port numbers relating to smtp 25,465,587,2525 - they are clear. – npr May 12 '18 at 10:21
  • 1
    I figured out there was an issue in my build which overwrote mail settings and hence it was failing. So my typo in my build was the evil ;) – npr May 12 '18 at 10:42

0 Answers0