我正在嘗試使用nodemailer模塊發送一些電子郵件。
這是我的程式:
const nodeMailer = require('nodemailer');
const randomSentence = require('random-sentence');
let mailList = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]'
]
async function test(){
let transporter = nodeMailer.createTransport({
host: 'smtp.mail.yahoo.com',
port: '465',
secure: true,
auth: {
user: '[email protected]',
pass: 'xxxxxxxxxxx'
}
});
try{
for (let index = 0; index < mailList.length; index ) {
let mailBody = randomSentence();
console.log(mailBody);
const contact = mailList[index];
await transporter.sendMail({
from: 'Node Mailer Test App <[email protected]>',
to: contact,
subject: 'test',
html: mailBody
})
}
console.log('All mails sent successfully!');
}catch(err){
console.log(`Error: ${err}`);
}
}
let forCount = 1;
for (let index = 0; index < forCount; index ) {
test();
}
如果我運行這個程式,它作業正常:
$ node debug.js
message 0: Ecmiw perpef suchuf runog olu duiduz remis ehere bevu fetuh leh areri gujin kuvug bifa.
message 1: Tuemigo lelsojkil we fenob meboceuti rifa ci ewiilu fisif uwois apovev seplep kotpi voug vek.
message 2: Suvne goeviru gigiwo dec pitak daiwa edo fifmij ne lad osezo wilomdo ore kebpenu nig zifvi gocpo.
message 3: Kibep pevkih cuf jar du lu li loj gicrioke fuwdij fo fo tiho pupaj pogpisu vogo uja.
All mails sent successfully!
但是如果我將forCount變數增加到 2,它會發送一些電子郵件,但我會收到以下錯誤:
Error: Error: Message failed: 554 6.6.0 Error sending message for delivery.
問題一:為什么會出現這個錯誤?
問題二:如何解決這個問題?
uj5u.com熱心網友回復:
最后我找到了我的問題的答案:)
看來這個問題與雅虎服務器有關,而不是我的代碼。也許雅虎使用積極的過濾演算法來減少其服務器上的流量。
順便說一句,如果您也遇到這個問題,我建議您遷移到另一個交付提供商(例如 Gmail)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/312923.html
上一篇:有沒有辦法從瀏覽器發送電子郵件?
