If pooling is used then Nodemailer keeps a fixed amount of connections open and sends the next message once a connection becomes available. It is mostly useful when you have a large number of messages that you want to send in batches or your provider allows you to only use a small amount of parallel connections.
To use pooled connections use the following options in transport configuration
The following options are deprecated and will be removed from future versions of Nodemailer.
Returns true if there are available connection slots
If transporter uses pooling then connections are kept open even if there is nothing to be sent. Connections that idle for longer than the socketTimeout will be closed automatically and reopened once there’s more mail to send. You can also use transporter.close() to clean up all connections.
let transporter = nodemailer.createTransport({pool: true,...});
// ...
transporter.close();
Emitted by the transporter object if connection pool has free connection slots. Check if a connection is still available with isIdle()
method (returns true
if a connection is still available). This allows to create push-like senders where messages are not queued into memory in a Node.js process but pushed and loaded through an external queue.
let messages = [..."list of messages"];
transporter.on("idle", function () {
// send next message from the pending queue
while (transporter.isIdle() && messages.length) {
transporter.sendMail(messages.shift());
}
});