1. Optimized Nodemailer Pooled Transport Configuration
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: 'relay.171mails.com',
port: 587,
secure: false, // TLS
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASS
},
pool: true, // Use connection pooling
maxConnections: 10, // Max concurrent sockets
maxMessages: 50, // Messages per connection before recycling
rateDelta: 1000, // Rate limit time window
rateLimit: 25 // Max messages per second
}); 2. Asynchronous Queue Processing with BullMQ
For production scale, pair Nodemailer with BullMQ and Redis to manage campaign bursts, retry failures with exponential backoff, and enforce strict hourly pacing:
const { Worker } = require('bullmq');
const emailWorker = new Worker('email-queue', async job => {
await transporter.sendMail({
from: '"171mails News" <news@yourdomain.com>',
to: job.data.recipient,
subject: job.data.subject,
html: job.data.html
});
}, { connection: redisConfig, concurrency: 10 }); 3. REST API Batch Dispatching
For microservices where opening persistent SMTP sockets is impractical, 171mails provides a high-speed JSON REST endpoint capable of accepting batches of 1,000 recipients in a single HTTP POST request.