-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.config.ts
48 lines (45 loc) · 1.17 KB
/
mail.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as aws from "@aws-sdk/client-ses";
import nodemailer from "nodemailer";
import { envVariables } from "./env.variables";
// configure AWS SDK
const ses = new aws.SES({
apiVersion: "2012-10-17",
region: envVariables.AWS_REGION,
credentials: {
secretAccessKey: envVariables.AWS_SES_SECRET_ACCESS_KEY,
accessKeyId: envVariables.AWS_SES_ACCESS_KEY_ID,
},
});
// create Nodemailer SES transporter
const transporter = nodemailer.createTransport({
SES: { ses, aws },
sendingRate: 1, // max 1 messages/second,
maxConnections: 1,
});
export const sendEmail = (
toAddresses: string,
subject: string,
emailBody: string
) => {
return new Promise(async (resolve, reject) => {
transporter.sendMail(
{
from: envVariables.FROM_EMIAL, // it should be verified email from AWS SES
to: toAddresses,
subject,
html: emailBody,
},
(err, info) => {
transporter.close();
resolve(true);
if (err) {
console.error(err);
} else {
console.log(new Date().toLocaleString(), info?.envelope);
console.log(info?.messageId);
}
}
);
resolve(true);
});
};