Npm Mail Notifier Error Handling

957 Views Asked by At

I am in a situation here. I am using an npm mail-notifier module . Its working fine. But i don't know how to do, when the Login is failed.

My code is

var imap = {
            user: "[email protected]",
            password: "pass",
            host: "imap.host.com"
        };
        notifier(imap).on('mail', function(mail) {
            test(mail);
        }).start();

        notifier(imap).on('error', function(err) {
            test(err);
        console.log("Error Occured");
        });

This is working fine when the login is correct. But I can't handle the error well. When An error occurs, I want the error function to be worked

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

Unfortunately Got the answer

var Imap = require('imap'),
    inspect = require('util').inspect;

var imap = new Imap({
            user: "username",
            password: "pass",
            host: "hostname"
    });



imap.once('ready', function() {
    console.log("Ready");
    var conn = {
        user: "username",
        password: "pass",
        host: "hostname"
    };
    notifier(conn).on('mail', function(mail) {
        test(mail);
    }).start();
});

imap.once('error', function(err) {
console.log("Inside Error");
  console.log(err);
});

imap.once('end', function() {
  console.log('Connection ended');
});

imap.connect();

This code done the duty...