【问题标题】:Antivirus is blocking nodemailer - Error: self signed certificate in certificate chain防病毒软件正在阻止 nodemailer - 错误:证书链中的自签名证书
【发布时间】:2019-05-08 03:21:39
【问题描述】:

我正在使用 nodemailer 发送电子邮件,但我的防病毒软件阻止了 nodemailer。当我关闭防病毒软件后,发送电子邮件就没有问题了。

有没有可能在不禁用杀毒软件的情况下使用 nodemailer 发送电子邮件的方法?

    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: 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' }

【问题讨论】:

    标签: gmail nodemailer antivirus


    【解决方案1】:

    在您的transporter 设置中,尝试添加以下内容:

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

    您现在应该可以在不禁用防病毒软件的情况下发送邮件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      • 2012-08-24
      • 2017-12-18
      • 2015-09-08
      • 2022-06-16
      • 2018-11-18
      相关资源
      最近更新 更多