mail-listener2 doesn't work

This is my code for the mail-listener file.

I call the startListening function in my main file, and I can read "Imap connected" in the console , but then, even if some email arrives, nothing happens.

Any Idea?

var MailListener = require("mail-listener2");

var mailListener = new MailListener({
  username: "myEmail@gmail.com",
  password: "myPassword",
  host: "imap.gmail.com",
  port: 993, // imap port
  tls: true,
  tlsOptions: { rejectUnauthorized: false },
  mailbox: "INBOX", // mailbox to monitor
  searchFilter: ["UNSEEN", "FLAGGED"], // the search filter being used after an IDLE notification has been retrieved
  markSeen: true, // all fetched email willbe marked as seen and not fetched next time
});

module.exports.startListening = function(){
    mailListener.start(); // start listening
}

// stop listening
//mailListener.stop();

mailListener.on("server:connected", function(){
  console.log("imapConnected");
});

mailListener.on("server:disconnected", function(){
  console.log("imapDisconnected");
});

mailListener.on("error", function(err){
  console.log(err);
});

mailListener.on("mail", function(mail, seqno, attributes){
  // do something with mail object including attachments
  console.log("emailParsed", mail);
  // mail processing code goes here
});

mailListener.on("attachment", function(attachment){
  console.log(attachment.path);
});

I had the same issue. The example doesn't work. I'm using mail-notifier instead:

var notifier = require('mail-notifier');

var imap = {
      user: "_example@example.com_",
      password: "password",
      host: "imap.gmail.com",
      port: 993,
      tls: true,
      tlsOptions: { rejectUnauthorized: false }
};

notifier(imap).on('mail',function(mail){
         console.log("GOT MAIL");
}).start();

Works like a charm