In our project, we are using 'imap' node module to connect to ms office outlook mail server and also we are doing many operations like fetch, getBoxes, search, setFlags etc using imap module.
Our server is trying to perform the above actions on mail server on per minute basis and there are many parallel flows are running to do so. Parallel flows are nothing but executing above actions parallely on imap server.
But after sometime all the flows starts returning 401 which imap module is returning. Our code is nearly like below:
var Imap = require('imap')
var imap = new Imap({
user: 'xxx@xx.com',
password: 'xxxx',
host: 'outlook.office365.com',
port: 993,
tls: true
});
imap.once('ready', function () {
imap.openBox('inbox', false, function (err, box) {
if (err) throw err;
var msgno = 1;
let fetchCheck = imap.seq.fetch(msgno + ':*', { bodies: [''] });
fetchCheck.on('message', function (msg, seqno) {
if (seqno == msgno) {
imap.seq.setFlags(seqno, 'Seen', function (err) {
if (err) {
return err;
} else {
imap.end();
}
});
}
})
fetchCheck.once('error', function (err) {
imap.end();
imap.closeBox();
});
});
});
imap.once('error', function (err) {
console.log(err);
});
imap.once('end', function () {
console.log('Done flagging message');
console.log('Connection ended');
});
imap.connect();
Like above code, we are also using the search, fetch, move actions to perform on mail server and all these actions are running in parallel. So after sometime, suddenly these parallel flows starts giving 401 Error: Timed out while authenticating with server.
Is there any connection restrictions to the office mail server or the limitation of 'imap' node module on the connection handling?