I'm trying to send some E-mails using nodemailer module.
here is my program:
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();
}
If I run this program, It works fine:
$ 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!
But if I increase the forCount
variable to 2, it will send some of emails but then I'll get below error:
Error: Error: Message failed: 554 6.6.0 Error sending message for delivery.
Question 1: Why does this error happen?
Question 2: How to resolve this issue?
CodePudding user response:
Finally I found answer of my question:)
It seems this problem is associated with Yahoo servers and not my code. Maybe Yahoo uses an aggressive filtering algorithm to decrease traffic over it's servers.
By the way if you face this problem too, I advise you to migrate to another delivery provider(e.g. Gmail).