How to get plan & html body of email in ImapFlow?

58 Views Asked by At

As I understand, I have to use client.download for each email, like:

const { content } = await client.download(message.uid, ['1', '2']);

But code just hangs on this line.

My current code is:

const client = new ImapFlow({
    host: 'imap.server.com',
    port: 993,
    secure: true,
    auth: {
        user: '', // Replace with your email address
        pass: '' // Replace with your password
    },
    logger: {
        level: 'info' // Set logging level as per your preference
    }
});

try {
    await client.connect();
    const lock = await client.getMailboxLock('INBOX');

    for await (const message of client.fetch('1:*', { envelope: true, bodyParts: true,
        bodyStructure: true })) {
        //console.log(message);
        console.log(message.bodyStructure.childNodes);
        //console.log(message.envelope);
    }

    lock.release();
} catch (err) {
    console.error('Error:', err);
} finally {
    await client.logout();
}
0

There are 0 best solutions below