-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathses_sendemail.js
76 lines (68 loc) · 1.93 KB
/
ses_sendemail.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
/*
ABOUT THIS NODE.JS EXAMPLE: This example works with the AWS SDK for JavaScript version 3 (v3),
which is available at https://github.com/aws/aws-sdk-js-v3. This example is in the 'AWS SDK for JavaScript v3 Developer Guide' at
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/s3-example-creating-buckets.html.
Purpose:
ses_sendemail.js demonstrates how to send an email using Amazon SES.
Running the code:
node ses_sendemail.js
*/
// snippet-start:[ses.JavaScript.email.sendEmailV3]
import { SendEmailCommand } from "@aws-sdk/client-ses";
import { sesClient } from "./libs/sesClient.js";
const createSendEmailCommand = (toAddress, fromAddress) => {
return new SendEmailCommand({
Destination: {
/* required */
CcAddresses: [
/* more items */
],
ToAddresses: [
toAddress,
/* more To-email addresses */
],
},
Message: {
/* required */
Body: {
/* required */
Html: {
Charset: "UTF-8",
Data: "HTML_FORMAT_BODY",
},
Text: {
Charset: "UTF-8",
Data: "TEXT_FORMAT_BODY",
},
},
Subject: {
Charset: "UTF-8",
Data: "EMAIL_SUBJECT",
},
},
Source: fromAddress,
ReplyToAddresses: [
/* more items */
],
});
};
const run = async () => {
const sendEmailCommand = createSendEmailCommand(
);
try {
return await sesClient.send(sendEmailCommand);
} catch (caught) {
if (caught instanceof Error && caught.name === "MessageRejected") {
/** @type { import('@aws-sdk/client-ses').MessageRejected} */
const messageRejectedError = caught;
return messageRejectedError;
}
throw caught;
}
};
// snippet-end:[ses.JavaScript.email.sendEmailV3]
export { run };