I'm creating a email verification system for my website and I'm using nodemailer to send the emails
However I'm concerned that the email won't be sent when multiple users ask for email verification
So to check for this, I created a simulation code which looks like this:
const express = require('express');
const app=express();
app.use(express.json());
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
host: "smtp-mail.outlook.com",
secureConnection: false,
port: 587,
pool:true,
maxConnections:2,
tls: {
ciphers:'SSLv3',
rejectUnauthorized: false
},
auth: {
user: 'generic-email@outlook.com',
pass: 'generic password'
}
});
app.get('/',async (req,res)=>{
for(var i=0;i<10;i++)
{
transporter.sendMail({
from: 'generic-email@outlook.com', // sender address
to: `generic-client@gmail.com`, // list of receivers
subject: "testing", // Subject line
text: "testing?", // plain text body
html: "<b>TESTING</b>", // html body
},(err,info)=>{
if(err)
console.log('ERROR=>',err);
else
console.log('INFO=>',info);
});
}
return res.send('Emails sent')
});
app.listen(3000,()=>{
console.log('Listening at Port 3000...');
});
as far as my knowledge goes the above code is stacking up 10 emails (due to the pool:true
) and sending 2 concurrently (due to the maxConnections:2
) at a time and theoretically it should work
as according to Microsoft outlook docs 3 concurrent connections are allowed
The service has various limits to prevent abuse and to ensure fair use. An additional limit is being added. Under the new limit, up to three concurrent connections are allowed to send email messages at the same time. If an application tries to send more than three messages at the same time by using multiple connections, each connection will receive the following error message:
but on running the code I randomly get this error for some of the sent emails:
Error: Message failed: 432 4.3.2 Concurrent connections limit exceeded. Visit https://aka.ms/concurrent_sending for more information. [Hostname=SG2PR01MB2186.apcprd01.prod.exchangelabs.com]
at SMTPConnection._formatError (C:\Users\name\node_modules\nodemailer\lib\smtp-connection\index.js:774:19)
at SMTPConnection._actionSMTPStream (C:\Users\name\node_modules\nodemailer\lib\smtp-connection\index.js:1651:34)
at SMTPConnection.<anonymous> (C:\Users\name\node_modules\nodemailer\lib\smtp-connection\index.js:1136:22)
at SMTPConnection._processResponse (C:\Users\name\node_modules\nodemailer\lib\smtp-connection\index.js:932:20)
at SMTPConnection._onData (C:\Users\name\node_modules\nodemailer\lib\smtp-connection\index.js:739:14)
at TLSSocket.SMTPConnection._onSocketData (C:\Users\name\node_modules\nodemailer\lib\smtp-connection\index.js:189:44)
at TLSSocket.emit (events.js:376:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9)
at TLSSocket.Readable.push (internal/streams/readable.js:223:10) {
code: 'EMESSAGE',
response: '432 4.3.2 Concurrent connections limit exceeded. Visit https://aka.ms/concurrent_sending for more information. [Hostname=SG2PR01MB2186.apcprd01.prod.exchangelabs.com]',
responseCode: 432,
command: 'DATA'
}
so what am I doing wrong here? and how do I make sure I can handle multiple email requests efficiently without nodemailer breaking down?