ImapIdleKeepConnection
use node-imap to connect to an imap server and handle all errors. Only emit mail event
Usage example:
const ImapIdleKeepConnection = require('imap-idle-keep-connection');
const imapConnection = new ImapIdleKeepConnection({
user: MailUser,
password: MailPassword,
xoauth2: token,
host: MailServer,
port: MailServerPort,
tls: true,
log: () => {},
debug: () => {},
error: () => {},
interval: 10000,
idleInterval: 120000,
forceNoop: false
});
imapConnection.on('mail', (imap, numNewMessages) => {
console.log('yay, got new mail!');
});
imapConnection.on('need-authentication', () => {
console.log('Authentication failed. Won\'t retry. Get new token (maybe, if oauth) and start again.');
imapConnection.endWatch();
});
imapConnection.on('error', error => {
console.log('Something went horribly wrong...', error);
});