process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0 not working

Viewed 3149

I'm using the node sendmail package which is giving me this error:

Error on connectMx for:  Error: self signed certificate
     at TLSSocket.onConnectSecure (_tls_wrap.js:1515:34)
     at TLSSocket.emit (events.js:400:28)
     at TLSSocket._finishInit (_tls_wrap.js:937:8)
     at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:709:12) {
   code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
}

So I put this in my code in like 5 places

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

Node says this warning when I run it:

Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.

Yet I still get the error message. It's coming from this code:

const {createConnection} = require('net');
createConnection(smtpPort, data[i].exchange);  // problem code
sock.on('error', function (err) {
    logger.error('Error on connectMx for: ', data[i], err);
    tryConnect(++i)
});

Is this a bug in NodeJS, or am I messing something up? Thanks for the help.

0 Answers
Related