Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mail-listener2 doesn't work

Tags:

node.js

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: "[email protected]",
  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);
});
like image 889
emacoder Avatar asked Aug 16 '14 23:08

emacoder


1 Answers

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

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

var imap = {
      user: "[email protected]_",
      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

like image 66
Coxy1989 Avatar answered Sep 18 '22 11:09

Coxy1989