错误:主机名/ IP与证书的altnames node.js不匹配

时间:2017-04-18 12:51:07

标签: nodemailer

我希望tom使用nodemailer从我的应用程序发送电子邮件,我的代码如下:

var smtpTransport = nodemailer.createTransport(smtpTransport({
          pool: true,
        host: 'smtp.myemailserver.com',
        port: 587,
        auth: {
            user: 'user@myDomain.com',
            pass: '******'
        }
}));
var mailOptions = {
    from: 'user@myDomain.com',
    to: 'user2@gmail.com',
    subject: 'test ',
    text: 'Hello world ',
    html: '<b>Hello world </b>'
    };

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

但是我得到的错误是我无法弄清楚的:

 [Error: Hostname/IP doesn't match certificate's altnames: "Host: smtp.myemailserver.com. is not in the cert's altnames: DNS:secure.emailsrvr.com, DNS:www.secure.myemailserver.com"]
      reason: 'Host: smtp.myemailserverr.com. is not in the cert\'s altnames: DNS:secure.myemailserver.com, DNS:www.myemailserver.com',
      host: 'smtp.myemailserver.com.',
      cert: 
       { subject: { OU: [Object], CN: 'secure.myemailserver.com' },
         issuer: 
          { C: 'GB',
            ST: 'Greater Manchester',
            L: 'Salford',
            O: 'COMODO CA Limited',
            CN: 'COMODO RSA Domain Validation Secure Server CA' },
         subjectaltname: 'DNS:secure.emailsrvr.com, DNS:www.secure.myemailserver.com',
         infoAccess: { 'CA Issuers - URI': [Object], 'OCSP - URI': [Object] }

我试图添加

tls { 
rejectUnauthorized: false 
} 

发送电子邮件选项,但这会阻止我的电子邮件,所以请任何帮助

1 个答案:

答案 0 :(得分:5)

不确定您是否在问题中错过了代码中的冒号,但它应该是:

tls: { 
    rejectUnauthorized: false 
}

根据我的经验,您需要了解证书名称不匹配的所有内容。整个运输选项应如下所示:

var smtpTransport = nodemailer.createTransport(smtpTransport({
    pool: true,
    host: 'smtp.myemailserver.com',
    port: 587,
    auth: {
        user: 'user@myDomain.com',
        pass: '******'
    },
    tls: {
        rejectUnauthorized: false
    }

另请注意,这会让您vulnerable to MITM attacks on SSL