Skip to main content

Use a mailbox

info

To use mailboxes, you need to configure an IMAP host and port

With MailboxJS, 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 { MailboxJs } from 'mailboxjs';
import { config } from './mbjs-config'; // MailboxJsConfig

const mbjs = await new MailboxJs(config).run(); // Connects to IMAP and SMTP server

const mailboxPath = 'INBOX'; // Mailbox path (name)
const mails = await mbjs.getMails(mailboxPath); // Get all mails from a mailbox

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

Delete mails

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

import { MailboxJs } from 'mailboxjs';
import { config } from './mbjs-config'; // MailboxJsConfig

const mbjs = await new MailboxJs(config).run(); // Connects to IMAP and SMTP server

const mailboxPath = 'INBOX'; // Mailbox path (name)
const mails = await mbjs.getMails(mailboxPath); // Get all mails from a mailbox

await mbjs.deleteMails(mailboxPath, { mails }); // Delete mails sended

This is another example to delete mails :

import { MailboxJs } from 'mailboxjs';
import { config } from './mbjs-config'; // MailboxJsConfig

const mbjs = await new MailboxJs(config).run(); // Connects to IMAP and SMTP server

const mailboxPath = 'INBOX'; // Mailbox path (name)
const mails = await mbjs.getMails(mailboxPath); // Get all mails from a mailbox

for (const mail of mails) {
await mail.delete();
}

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