メインコンテンツまでスキップ

EmailService

説明

このサービスは、AWS SES (Simple Email Service)を使用してメールを送信するように設計されています。

メソッド

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

メールメッセージを作成し、送信のためにすぐにキューに入れます。

基本的な例

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,
});

CCと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>",
});

添付ファイル付き

添付ファイルオブジェクトの配列を指定することで、メールにファイルを添付できます:

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",
},
],
});

複数の添付ファイル

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インターフェース

プロパティ必須説明
fromAddrstringいいえ送信者メールアドレス(指定しない場合はデフォルトを使用)
toAddrsstring[]はい受信者メールアドレスのリスト
ccAddrsstring[]いいえCC受信者
bccAddrsstring[]いいえBCC受信者
subjectstringはいメール件名
bodystringはいHTMLとしてのメール本文
replyToAddrsstring[]いいえ返信先アドレス
attachmentsAttachment[]いいえ添付ファイル

Attachmentインターフェース

プロパティ必須説明
filenamestringはい受信者に表示されるファイル名
contentBufferはいBufferとしてのファイル内容
contentTypestringいいえMIMEタイプ(例:'application/pdf')