-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathses-sendMail-v3.js
51 lines (46 loc) · 1.17 KB
/
ses-sendMail-v3.js
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
49
50
51
const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");
require('dotenv').config();
const SES_CONFIG = {
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
region: process.env.AWS_SES_REGION,
};
// Create SES service object.
const sesClient = new SESClient(SES_CONFIG);
const sendEmail = async (recipientEmail, name) => {
let params = {
Source: process.env.AWS_SES_SENDER,
Destination: {
ToAddresses: [
recipientEmail
],
},
ReplyToAddresses: [],
Message: {
Body: {
Html: {
Charset: 'UTF-8',
Data: '<h1>This is the body of my email!</h1>',
},
Text: {
Charset: "UTF-8",
Data: "This is the body of my email!"
}
},
Subject: {
Charset: 'UTF-8',
Data: `Hello, ${name}!`,
}
},
};
try {
const sendEmailCommand = new SendEmailCommand(params);
const res = await sesClient.send(sendEmailCommand);
console.log('Email has been sent!', res);
} catch (error) {
console.error(error);
}
}
sendEmail("webwizard0808@gmail.com", "Web Wizard");