Multiple mail accounts
Closed this issue · 0 comments
wiesson commented
Hi, can you add a rough / simple example how to listen to multiple mail accounts? :)
//Edit: ok, I figured it out by self.
var data = [
{'usern': 'foo@bar.de', 'passw': 'bar'},
{'usern': 'foo@bar.de', 'passw': 'bar'},
{'usern': 'foo@bar.de', 'passw': 'bar'}
(...)
];
data.forEach(function (v) {
var mailListener = new MailListener({
username: v.usern,
password: v.passw,
(...)
)};
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);
});
});