node.js – Node IMAP ECONNRESET with Mail-in-a-box email

When I create an IMAP connection with node-imap module with a Mail-in-a-box (MIAB) email, after a few minutes, I get the ECONNRESET error. I want to know if it is a fault in the connection configuration, or is it from MIAB server side that will disconnect the connection if it has been idle for too long.

Here is my IMAP connection configuration:

          port: 993,
          tls: true,
          authTimeout: 30000,
          connTimeout: 30000,
          keepalive: {
            forceNoop: true,
          tlsOptions: {
            rejectUnauthorized: false,

And this is the error I got:

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:209:20) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read',
  source: 'socket'

I am using the mail-notifier module, which is a wrapper of node-imap module. This is the code where I register for events in the IMAP connection

const notifier = Notifier(imap);
  .on("end", () => notifier.start())
  .on("connected", () => {
    console.log(`Connected IMAP: ${user}`);
  .on("mail", (mail) => {
    this.onMail(mail, user);
  .on("error", (e: any) => {
    console.log(`IMAP error: ${user}, time: ${}`);
    setTimeout(() => {
    }, 5000);

Read more here: Source link