Search code examples
node.jsemailnodemailer

nodemailer error self signed certificate in certificate chain


My gmail account also got lesssecureapps status

const transporter = nodemailer.createTransport({
      service: 'gmail',
      auth: {
        user: worker_email,
        pass: worker_pass
      }
})

when im trying

transporter.sendEmail(options)

i got an error:

Error: self signed certificate in certificate chain
at TLSSocket.onConnectSecure (_tls_wrap.js:1321:34)
at TLSSocket.emit (events.js:223:5)
at TLSSocket._finishInit (_tls_wrap.js:794:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:608:12) {
  code: 'ESOCKET',
  command: 'CONN'
}

Solution

  • Please see this brief answer: https://stackoverflow.com/a/64913747/5172977

    Basically, it likely has to do with your transport settings.

    Here is the example for the development environment with Ethereal.email

    const transporter = nodemailer.createTransport({
        host: 'smtp.ethereal.email',
        port: 587,
        auth: {
            user: '[email protected]',
            pass: 'password'
        },
        // === add this === //
        tls : { rejectUnauthorized: false }
    });