Skip to main content
Version: 0.2.0

Send Mail

Since mailables and the transporters are two different entities, Mailman separates these concerns by providing 2 sets of APIs(Build Mail and Send Mail). In the previous section, you looked at the various APIs to build Mail. This section introduces APIs that help send the mail.

Send()

To send a mail, we first call the init() method on Mailman. This creates a new Mailman instance for us, on which we can call the to(recipient) to specify the mail recipient(s) and the send(mailMessage) method to actually send the mail.

import { Mailman, MailMessage } from '@squareboat/nest-mailman';

const mail = MailMessage.init()
.greeting('Hello admin')
.line('One of your invoices #12345 has been paid!')
.action('Check invoice', 'https://squareboat.com')
.line('Please let us know if you are facing any issue!')
.subject('INVOICE PAID: #12345');

Mailman.init()
.to('opensource@squareboat.com') // OR .to(['id1@email.com', 'id2@email.com'])
.send(mail);
info

MailMessage is used for building mails whereas Mailman is used for transporting emails.

Override Sender

To override the from address specified when configuring Mailman, simpy call the from(sender) method

Mailman.init()
.to('opensource@squareboat.com') // OR .to(['id1@email.com', 'id2@email.com'])
.from('no-reply@email.com')
.send(mail);

Marking Carbon Copies

To add cc or bcc to your mail, you can make use of the cc() and bcc() methods passing in an email or array of emails.

Mailman.init()
.to('opensource@squareboat.com') // OR .to(['id1@email.com', 'id2@email.com'])
.cc('cc@email.com') // string or string[]
.bcc('bcc@email.com') // string or string[]
.send(mail);