4

I'm trying to send an email using nodemailer.

In my LAN there is a SMTP server listening on port 25. If I use telnet, it works fine.

My js script is:

this.transporter.sendMail(mailOptions, function (error, info) {
        if (error) {
            console.log(JSON.stringify(error));
            return callback(error, null);
        }

        console.log(JSON.stringify(info));

        return callback(null, true);
});

It only prints: {"code":"ESOCKET","command":"CONN"}. What does it mean?

Thanks in advance

Domenico Ventura
  • 79
  • 1
  • 1
  • 9

1 Answers1

16

Per https://github.com/nodemailer/nodemailer/issues/889#issuecomment-488267379 (and it's follow-ups):

same problem here. resolved it by using IP address as host, see https://nodemailer.com/smtp/#general-options

For us it seems to be related to throttling as circa 140 messages go through in a batch while the remainder get this error (and all are being sent to the same email address, so no issue re: bad email addresses). Changing to an IP didn't solve the issue (maybe because the SMTP is on AWS?).

What did eventually work for us was this - https://stackoverflow.com/a/55187729/235704

The below code change fixed the issue. Added this to the createTransport()

tls: {rejectUnauthorized: false}

Code:-

// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
    host: 'host',
    port: 25,
    secure : false, // true for 465, false for other ports
    auth: {
        user: 'user',
        pass: 'password'
    },
    tls: {
        // do not fail on invalid certs
        rejectUnauthorized: false
    },
});

It seems that, in our providers case, their certificates do not cover all of the IPs they are being served from on AWS.

Campbeln
  • 2,880
  • 3
  • 33
  • 33