When sending a large number of emails, implement rate limiting or throttling to avoid being marked as spam or hitting rate limits of your email provider. Libraries like bottleneck can help with this.
Example with Bottleneck:
const Bottleneck = require('bottleneck');
const limiter = new Bottleneck({
maxConcurrent: 2,
minTime: 500 // milliseconds
});
const sendEmail = limiter.wrap(async (emailOptions) => {
await transporter.sendMail(emailOptions);
});
// Add jobs to send emails
sendEmail({ to: 'recipient@example.com', subject: 'Throttled Email', text: 'This email is sent with throttling.' });
Leave a Reply