IMAP Client for Node.js extracted from NodemailerApp project.
The focus for ImapFlow is to provide easy to use API over IMAP.
First install the module from npm:
$ npm install imapflow
next import the ImapFlow class into your script:
const { ImapFlow } = require('imapflow');
All ImapFlow methods use Promises, so you need to wait using await
or wait for the then()
method to fire until you get the response.
const { ImapFlow } = require('imapflow');
const client = new ImapFlow({
host: 'ethereal.email',
port: 993,
secure: true,
auth: {
user: '[email protected]',
pass: 'mW6e4wWWnEd3H4hT5B'
}
});
const main = async () => {
// wait until client connects and authorizes
await client.connect();
// select a mailbox
await client.mailboxOpen('INBOX');
// fetch latest message source
let message = await client.fetchOne('*', { source: true });
console.log(message.source.toString());
// list subjects for all messages
// uid value is always included in FETCH response, envelope strings are in unicode.
for await (let message of client.fetch('1:*', { envelope: true })) {
console.log(`${message.uid}: ${message.envelope.subject}`);
}
// log out and close connection
await client.logout();
};
main().catch(err => console.error(err));
ImapFlow has TS typings set for compatible editors.
© 2020 Andris Reinman
Licensed for evaluation use only