Skip to main content

Use a mailbox

With IMAP mailbox, you can use all your mailboxes.

You can get, delete, see and unsee mails.

Get mails

There is a code example to get mails from mailbox INBOX :

import Imap from 'imap-mailbox';
import { config } from './imap-config'; // ImapConfig

const imap = new Imap(config);
await imap.start(); // Connect to IMAP server

const mailboxPath = 'INBOX'; // Mailbox path (name)
const mails = await imap.getAllMails(mailboxPath);

console.log(mails); // Log an array of Mail

Delete mails

There is a code example to delete mails from mailbox INBOX :

import Imap from 'imap-mailbox';
import { config } from './imap-config'; // ImapConfig

const imap = new Imap(config);
await imap.start(); // Connect to IMAP server

const mailboxPath = 'INBOX'; // Mailbox path (name)
const mails = await imap.getAllMails(mailboxPath);

await imap.deleteMails(mailboxPath, { mails });

Now that you can manage a mailbox, we can continue to watching inboxes in the next step.