2017-04-18 93 views
0

我想湯姆使用nodemailer我的應用程序發送電子郵件,我的代碼看起來是這樣的:錯誤:主機名/ IP不匹配證書的altnames Node.js的

var smtpTransport = nodemailer.createTransport(smtpTransport({ 
      pool: true, 
     host: 'smtp.myemailserver.com', 
     port: 587, 
     auth: { 
      user: '[email protected]', 
      pass: '******' 
     } 
})); 
var mailOptions = { 
    from: '[email protected]', 
    to: '[email protected]', 
    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 
} 

電子郵件選項,但會要求擋住了我的電子郵件,所以請任何幫助

+0

這是什麼意思「阻止我的電子郵件」?請提供帶有tls選項的日誌。 – Francesco

+0

[發送電子郵件與nodemailer](https://stackoverflow.com/questions/29099582/sending-emails-with-nodemailer) –

回答

1

不知道你錯過了在你的代碼結腸像你的問題,但它應該是:

tls: { 
    rejectUnauthorized: false 
} 

根據我的經驗,這就是你需要避開證書名稱不符。整個運輸方案應該是這樣的:

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

同時請記住這個讓你vulnerable to MITM attacks on SSL

+0

得到錯誤響應 的可能重複: 「535個不正確的認證數據」 – Ash

+0

響應 : 「 535驗證數據不正確「 – Ash

相關問題