import { SendEmailCommand, SESv2Client } from "@aws-sdk/client-sesv2"; import { AwsContext } from "./context.ts"; import { Mail, MailDeliverer } from "../mail.ts"; export class AwsMailDeliverer extends MailDeliverer { private _ses; constructor(readonly aws: AwsContext) { super("aws"); const { region, credentials } = aws; this._ses = new SESv2Client({ region, credentials }); } protected override async doDeliver(mail: Mail): Promise { let awsMessageId: string | undefined; try { const sendCommand = new SendEmailCommand({ Content: { Raw: { Data: mail.toUtf8Bytes() }, }, }); const res = await this._ses.send(sendCommand); awsMessageId = res.MessageId; } catch (cause) { mail.throwDeliverError( this, "failed to call send-email api of aws.", cause, ); } if (awsMessageId == null) { mail.setDelivered(this, new Error("No message id is returned from aws.")); } mail.awsMessageId = awsMessageId ?? null; } }