2017-07-03 80 views
0

每當我跑,我發現了錯誤代碼「錯誤:問候語從未在SMTPConnection._formatError收到......」發送郵件與nodemailer

function automatedMailSender(req,res){ 

var mailOptions = { 
    from: "abc <[email protected]>", // sender address 
    to: '[email protected]', // list of receivers 
    subject: 'Hello ', // Subject line 
    text: 'Hello world ?', // plain text body 
    html: '<b>Hello world ?</b>' // html body 
}; 


var mailer=nodemailer.createTransport({ 
    host: 'mail.test.com', 
    port: 465, 
    secure: false, // secure:true for port 465, secure:false for port 587 
    auth: { 
     user: '[email protected]', 
     pass: '1234' 
    } 
}); 

mailer.sendMail(mailOptions, (error, response)=>{ 
    if(error){ 
     console.log('mail not sent \n',error); 
    } 
    else{ 
     console.log("Message sent: " ,response.message); 
    } 
}); 
} 

我做錯了什麼代碼。請幫助

+0

是真的請張貼完整的錯誤。 –

回答

0

嘗試類似的東西,這對我來說很好地工作:

//Create reusable transporter object using the default SMTP transport 
var transporter = nodemailer.createTransport(
'smtps://USERNAME%40gmail.com:[email protected]'); 

// setup e-mail data 
var mailOptions = { 
     from: '"Michel " <[email protected]>', // sender address 
     to: '[email protected]', // list of receivers 
     subject: 'Hello', // Subject line 
     text: 'Bonjour!' // plaintext body 
     }; 

// send mail with defined transport object 

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

如果仍然不工作,你有一個小政黨成員here

0
tls:{ 
     rejectUnauthorized:false 
    } 

通過使用郵件程序變量上述代碼固定它。 謝謝你們

0

在正確的答案在你的代碼

port: 465, 
secure: false, // secure:true for port 465, secure:false for port 587 

的值「安全」應爲端口465

相關問題