Skip to main content

EmailService

Description

This service is designed to send emails using AWS SES (Simple Email Service).

Methods

async sendEmail(msg: EmailNotification): Promise<any>

Composes an email message and immediately queues it for sending.

Basic Example

const email = "cat@example.com";
const subject = "Welcome to MBC CQRS serverless framework!";
const body = "<p>Enjoy</p>";

await this.mailService.sendEmail({
toAddrs: [email],
subject,
body,
});

With CC and BCC

await this.mailService.sendEmail({
toAddrs: ["recipient@example.com"],
ccAddrs: ["cc@example.com"],
bccAddrs: ["bcc@example.com"],
subject: "Meeting Invitation",
body: "<p>Please join our meeting.</p>",
});

With Attachments

You can attach files to emails by providing an array of attachment objects:

await this.mailService.sendEmail({
toAddrs: ["recipient@example.com"],
subject: "Report Attached",
body: "<p>Please find the attached report.</p>",
attachments: [
{
filename: "report.pdf",
content: pdfBuffer,
contentType: "application/pdf",
},
],
});

Multiple Attachments

await this.mailService.sendEmail({
toAddrs: ["recipient@example.com"],
subject: "Documents",
body: "<p>Please find the attached documents.</p>",
attachments: [
{
filename: "document.pdf",
content: pdfBuffer,
contentType: "application/pdf",
},
{
filename: "image.jpg",
content: imageBuffer,
contentType: "image/jpeg",
},
{
filename: "data.csv",
content: csvBuffer,
contentType: "text/csv",
},
],
});

EmailNotification Interface

PropertyTypeRequiredDescription
fromAddrstringNoSender email address (uses default if not specified)
toAddrsstring[]YesList of recipient email addresses
ccAddrsstring[]NoCC recipients
bccAddrsstring[]NoBCC recipients
subjectstringYesEmail subject line
bodystringYesEmail body as HTML
replyToAddrsstring[]NoReply-to addresses
attachmentsAttachment[]NoFile attachments

Attachment Interface

PropertyTypeRequiredDescription
filenamestringYesFilename shown to recipient
contentBufferYesFile content as Buffer
contentTypestringNoMIME type (e.g., 'application/pdf')