2016-12-04 44 views
3

我使用Nodemailer 2.6.4在節點6.9.1不支持的配置,降級Nodemailer到V0.7.1

var nodemailer = require("nodemailer"); 
var wellknown = require('nodemailer-wellknown'); 

var transporter = nodemailer.createTransport("SMTP",{ 
    service: "yahoo", 
    auth: { 
     user: ",,,@yahoo.com", 
     pass: ",,,,,," 
    } 
}); 

transporter.sendMail({ 

      from  : sender_address, 
      to   : recipients, 
      reply_to : "<[email protected]>", 
      subject  : "The subject", 
      text  : "a text message" 
     }, 
     function(error, response) {} 
); 

當運行它,我收到此錯誤:

Error: Unsupported configuration, downgrade Nodemailer to v0.7.1 to use it

我想學會使用最新版本,那麼我必須改變什麼?

回答

1

您當前的代碼是一箇舊版本Nodemailer,並與更新的版本不兼容。給定example in the README應該沒有最新的版本的所有問題:

var nodemailer = require('nodemailer'); 

var smtpConfig = { 
    host: 'smtp.mail.yahoo.com', 
    port: 465, 
    secure: true, 
    auth: { 
     user: '...', 
     pass: '...' 
    } 
}; 

var transporter = nodemailer.createTransport(smtpConfig); 

var mailOptions = { 
    from: '...', 
    to: '...', 
    subject: '...', 
    text: '...', 
    html: '...' 
}; 

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

正如你所看到的,不再需要在「SMTP」在createTransport字符串。

我對雅虎的SMTP settings進行了改編。您也可以像您目前所做的那樣使用nodemailer-wellknown,在這種情況下,請將smtpConfig替換爲:

var smtpConfig = { 
    service: 'yahoo', 
    auth: { 
     user: '...', 
     pass: '...' 
    } 
}; 
1

刪除第一個變量:

nodemailer.createTransport("SMTP",{

var transporter = nodemailer.createTransport({ 
    service: "yahoo", 
    auth: { 
     user: ",,,@yahoo.com", 
     pass: ",,,,,," 
    } 
}); 

通過檢查node-mailer線的源代碼273

https://github.com/nodemailer/nodemailer/blob/829ccf16eca3da686abf575eaaeea23736f85732/lib/nodemailer.js#L273

可以看到第一可變不能是

當我遇到錯誤時,我在模塊的源代碼中搜索錯誤,然後我可以看到觸發它的原因。

在你的情況下,你可以看到,一些人已經報告它的問題:

相關問題