Antivirus is blocking nodemailer - Error: self signed certificate in certificate chain

大憨熊 提交于 2021-01-03 07:31:05

问题


I'm using nodemailer to send emails, but my antivirus block the nodemailer. When I turn off the antivirus there is no problem sending emails.

Are there any possible way to send emails useing nodemailer without disabling antivirus?

    const transporter = nodemailer.createTransport({
        host: 'smtp.gmail.com',
        port: 465,
        secure: true,
        auth: {
            user: 'username@gmail.com',
            pass: 'password'
        }
    });

    var mailOptions = {
        from: 'username@gmail.com',
        to: "to',
        subject: 'subject',
        html: '<div></div>'
    };

    transporter.sendMail(mailOptions, function (error, info) {
        if (error) {
            console.log(error)
        } else {
            console.log('Email sent: ' + info.response);
        }
    });

Error Message ->

    { Error: self signed certificate in certificate chain
       at TLSSocket.<anonymous> (_tls_wrap.js:1105:38)
       at emitNone (events.js:106:13)
       at TLSSocket.emit (events.js:208:7)
       at TLSSocket._finishInit (_tls_wrap.js:639:8)
       at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:469:38) code: 'ESOCKET', 
       command: 'CONN' }

回答1:


In your transporter settings, try adding the following:

 const transporter = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
        user: 'username@gmail.com',
        pass: 'password'
    },
    // === add this === //
    tls : { rejectUnauthorized: false }
});

You should now be able to send without disabling your antivirus.



来源:https://stackoverflow.com/questions/56033066/antivirus-is-blocking-nodemailer-error-self-signed-certificate-in-certificate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!