2

I'm using node.js with nodemailer on a fresh ubuntu plesk root server.

When trying to send an email like this:

module.exports = {
    SMTP_HOST: 'host',
    SMTP_USER: 'username',
    SMTP_PASS: 'password',
};

let transporter = nodemailer.createTransport({
  host: SMTP_HOST,
  //port: 465,
  port: 587,
  secure: true,
  auth: {
      user: SMTP_USER,
      pass: SMTP_PASS
  },
  tls:{
    rejectUnauthorized:false  // if on local
  }
});

... I'm getting this error message:

{ Error: connect ECONNREFUSED ip-adress:587
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
errno: 'ECONNREFUSED',
code: 'ECONNECTION',
syscall: 'connect',
address: 'ip-adress',
port: 587,
command: 'CONN' }

How can I send emails via a plesk root server?

... if I use port 465 I'm getting this error:

{ Error: Data command failed: 550 5.7.1 Command rejected
at SMTPConnection._formatError (/home/project/node_modules/nodemailer/lib/smtp-connection/index.js:605:19)
at SMTPConnection._actionDATA (/home/project/node_modules/nodemailer/lib/smtp-connection/index.js:1454:34)
at SMTPConnection._responseActions.push.str (/home/project/node_modules/nodemailer/lib/smtp-connection/index.js:1426:26)
at SMTPConnection._processResponse (/home/project/node_modules/nodemailer/lib/smtp-connection/index.js:764:20)
at SMTPConnection._onData (/home/project/node_modules/nodemailer/lib/smtp-connection/index.js:570:14)
at TLSSocket._socket.on.chunk (/home/project/node_modules/nodemailer/lib/smtp-connection/index.js:522:47)
at TLSSocket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at TLSSocket.Readable.push (_stream_readable.js:224:10)
at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
code: 'EENVELOPE',
response: '550 5.7.1 Command rejected',
responseCode: 550,
command: 'DATA' }  
Philipp M
  • 3,306
  • 5
  • 36
  • 90
  • Something is wrong with your connection options. Your error mentions port `587` but your options specify port `465`. – ahwayakchih Oct 16 '19 at 14:48
  • Also, have you tried `sendmail` transport for Nodemailer? https://nodemailer.com/transports/sendmail/ – ahwayakchih Oct 16 '19 at 14:48
  • it should have been port: 587 ... I previously tried 465 but that didn't work either. Plesk says to use 587 https://docs.plesk.com/en-US/obsidian/administrator-guide/59430/ ... but my hoster says (in general) to use 465 for outgoing mails ... – Philipp M Oct 16 '19 at 14:51
  • ... no I haven't use sendmail ... I'll give it a try – Philipp M Oct 16 '19 at 14:54
  • Your updated error for port 465 looks more like a data error, not a connection error. So maybe try to keep port 465, but change various nodemailer's options regarding data instead? Check this reported issue: https://github.com/nodemailer/nodemailer/issues/145 – ahwayakchih Oct 16 '19 at 15:02
  • It was indeed the missing sendmail: true part. Happy to accept your answer if you post one :-) – Philipp M Oct 16 '19 at 15:37
  • I'm glad that it helped, by i was just guessing, so it was not really an answer on my part :). – ahwayakchih Oct 16 '19 at 15:43

1 Answers1

2

Adding sendmail: true (https://nodemailer.com/transports/sendmail/) solved the issue:

let transporter = nodemailer.createTransport({
  sendmail: true,
  newline: 'unix',
  path: '/usr/sbin/sendmail',
  host: SMTP_HOST,
  //port: 465,
  port: 587,
  secure: true,
  auth: {
      user: SMTP_USER,
      pass: SMTP_PASS
  },
  tls:{
    rejectUnauthorized:false  // if on local
  }
});
Philipp M
  • 3,306
  • 5
  • 36
  • 90