forked from chirag04/mail-listener2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
41 lines (34 loc) · 937 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var MailListener = require('./');
var mailListener = new MailListener({
username: 'xxx',
password: 'xxx',
host: 'imap.gmail.com',
port: 993,
tls: true,
tlsOptions: { rejectUnauthorized: false },
mailbox: 'INBOX',
fetchUnreadOnStart: true,
attachments: true,
attachmentOptions: { directory: 'attachments/' },
fetchingPauseThreshold: 5 * 1048576, // 5 mb
});
mailListener.start();
mailListener.on('server:connected', function () {
console.log('imapConnected');
});
mailListener.on('server:disconnected', function () {
console.log('imapDisconnected');
setTimeout(function () {
console.log('Trying to establish imap connection again');
mailListener.restart();
}, 5 * 1000);
});
mailListener.on('error', function (err) {
console.log(err);
});
mailListener.on('mail', function (mail) {
console.log(mail);
});
mailListener.on('attachment', function (attachment) {
console.log(attachment);
});