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);
});
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With