-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-new-email-simple.js
More file actions
25 lines (23 loc) · 1.01 KB
/
Copy pathfetch-new-email-simple.js
File metadata and controls
25 lines (23 loc) · 1.01 KB
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
const imapSimple = require('imap-simple');
const util = require('util');
const _ = require('lodash');
const emailSettings = require('./credentials/email_imap.json');
module.exports = function fetchNewEmail() {
return imapSimple.connect({imap: emailSettings}).then((connection) => {
return connection.openBox('INBOX').then(() => {
// fetch all unread messages since before I wrote this script
//const f = imapClient.seq.fetch([ 'UNSEEN', ['SINCE', 'Jan 1, 2020'] ],
return connection.search([ 'UNSEEN', ['SINCE', 'Jan 1, 2020'] ], {
bodies: ['HEADER.FIELDS (FROM TO SUBJECT DATE)'],
struct: true,
markSeen: false,
});
}).then((messages) => {
const emails = [];
messages.forEach((message) => {
//const parts = imapSimple.getParts(message.attributes.struct);
console.log('email info is', JSON.stringify(message, null, 2));
});
});
});
};