I am trying to send an email to multiple recipients ( about 3.000 ). All emails are stored in my DB ( Mongo ). So I make a query that return all the email addresses, and I use async to send all the emails, like:
function _sendEmail(params, callback) {
async.each(params.email, function(user, cb) {
const mailOptions = {
from: sender
to: user,
subject: Subject,
text: 'Hello Word',
};
app.transporter.sendMail(mailOptions, function(err, response) {
if(err) console.log(err);
else console.log(response);
cb();
});
}, callback);
}
I am creating my nodemailer transporte in my app.js, ,like so:
const transporter = nodemailer.createTransport(smtpTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: senderMail,
pass: senderMailPassword
}
}));
When I try to send this to only 10 mails, it works just fine, but when I try to send to all the emails in my DB, I am getting this error a bunch of times:
{ [Error: Data command failed: 421 4.7.0 Temporary System Problem. Try again later (WS). g32sm7412411qtd.28 - gsmtp]
code: 'EENVELOPE',
response: '421 4.7.0 Temporary System Problem. Try again later (WS). g32sm7412411qtd.28 - gsmtp',
responseCode: 421,
command: 'DATA' }
Am I missing something? Do I need to set something to be able to send lots os emails in a small period of time? I am using a gmail account to do that!
Thanks in advance!