Skip to main content

Send mails

info

To send mails, you need to configure a SMTP host and port

Sending mails is the easiest part of MailboxJS.

Sending mails

This is a code example for sending mails :

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

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

mbjs.send('Name <tomail@mail.domain>', 'My subject here', 'My text here'); // Sends mail

Sending HTML mails

This is a code example for sending HTML mails :

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

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

mbjs.sendHtml(
'Name <tomail@mail.domain>',
'My subject here',
'My alternative text here',
'My <b>HTML</b> text<br />Here!',
); // Sends HTML mail

Sending mails with attachments

Sending attachments is really easy.

There is an example :

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

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

const attachment = new Attachment('hello.txt', 'hello world');

mbjs.send(
'Name <tomail@mail.domain>',
'My subject here',
'My text here',
attachment,
); // Sends mail

We will see that in the next step.