2021-09-15 22:56:16 +00:00
|
|
|
import type { SendEmailRequest } from "aws-sdk/clients/ses";
|
|
|
|
import { Credentials, SES } from "aws-sdk";
|
|
|
|
import { getConfig } from "blitz";
|
|
|
|
|
|
|
|
const { serverRuntimeConfig } = getConfig();
|
|
|
|
|
|
|
|
const credentials = new Credentials({
|
|
|
|
accessKeyId: serverRuntimeConfig.awsSes.accessKeyId,
|
|
|
|
secretAccessKey: serverRuntimeConfig.awsSes.secretAccessKey,
|
|
|
|
});
|
|
|
|
const ses = new SES({ region: serverRuntimeConfig.awsSes.awsRegion, credentials });
|
|
|
|
|
|
|
|
type SendEmailParams = {
|
2021-10-26 21:34:21 +00:00
|
|
|
text: string;
|
|
|
|
html: string;
|
2021-09-15 22:56:16 +00:00
|
|
|
subject: string;
|
|
|
|
recipients: string[];
|
|
|
|
};
|
|
|
|
|
2021-10-26 21:34:21 +00:00
|
|
|
export async function sendEmail({ text, html, subject, recipients }: SendEmailParams) {
|
2021-09-15 22:56:16 +00:00
|
|
|
const request: SendEmailRequest = {
|
|
|
|
Destination: { ToAddresses: recipients },
|
|
|
|
Message: {
|
|
|
|
Body: {
|
|
|
|
Text: {
|
|
|
|
Charset: "UTF-8",
|
2021-10-26 21:34:21 +00:00
|
|
|
Data: text,
|
|
|
|
},
|
|
|
|
Html: {
|
|
|
|
Charset: "UTF-8",
|
|
|
|
Data: html,
|
2021-09-15 22:56:16 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Subject: {
|
|
|
|
Charset: "UTF-8",
|
|
|
|
Data: subject,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Source: serverRuntimeConfig.awsSes.fromEmail,
|
|
|
|
};
|
|
|
|
|
|
|
|
await ses.sendEmail(request).promise();
|
|
|
|
}
|