0

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 = [
    'gmans8951@gmail.com',
    'hamideh.2020ha@gmail.com',
    'mali1370.goli@gmail.com',
    'golgolniamilad@gmail.com'
]


async function test(){    

    let transporter = nodeMailer.createTransport({
        host: 'smtp.mail.yahoo.com',
        port: '465',
        secure: true,
        auth: {
            user: 'milad1395@yahoo.com',
            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 <milad1395@yahoo.com>',
                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?

milad
  • 1,854
  • 2
  • 11
  • 27

2 Answers2

0

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).

milad
  • 1,854
  • 2
  • 11
  • 27
0

Don't be so hasty to blame Yahoo. Try adding logger and enable debug in the transport to print to console the full SMTP communication so that you can actually troubleshoot what the issue may be. See below transport.

One possible issue is you need to create an app password from your Yahoo account security page. I think this is required or you wont be able to authenticate. An alternative is to play around with yahoo settings and find somewhere to allow insecure logins which will allow you to put in your normal password. I think Gmail has this somewhere too.

Anyway, I copied your code and modified it to only send a single message instead of 4. Works fine for me, likely because of the App Password I mentioned. Also works on port 587 just fine.

let transporter = nodeMailer.createTransport({
    logger: true,
    debug: true,
    host: 'smtp.mail.yahoo.com',
    port: 465,
    secure: true, // true if using port 465 and then we want to STARTTLS, should be false if using port 587
    auth: {
        user: 'some_user@yahoo.com',
        pass: 'create_app_pass_from_yahoo_security_page'
    }
});
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
  • In case of a single message, it works fine for me too. Please send 4 messages and report the result. – milad Apr 14 '22 at 09:46