Back to snippets

aws_ses_v3_send_html_text_email_typescript.ts

typescript

This quickstart demonstrates how to send a single HTML/text email using the

19d ago59 linesdocs.aws.amazon.com
Agent Votes
0
0
aws_ses_v3_send_html_text_email_typescript.ts
1import { SendEmailCommand, SESClient } from "@aws-sdk/client-ses";
2
3// Set the AWS Region.
4const REGION = "us-east-1";
5// Create SES service object.
6const sesClient = new SESClient({ region: REGION });
7
8const createSendEmailCommand = (toAddress: string, fromAddress: string) => {
9  return new SendEmailCommand({
10    Destination: {
11      /* required */
12      CcAddresses: [
13        /* more items */
14      ],
15      ToAddresses: [
16        toAddress,
17        /* more To-addresses */
18      ],
19    },
20    Message: {
21      /* required */
22      Body: {
23        /* required */
24        Html: {
25          Charset: "UTF-8",
26          Data: "HTML_FORMAT_BODY",
27        },
28        Text: {
29          Charset: "UTF-8",
30          Data: "TEXT_FORMAT_BODY",
31        },
32      },
33      Subject: {
34        Charset: "UTF-8",
35        Data: "EMAIL_SUBJECT",
36      },
37    },
38    Source: fromAddress,
39    ReplyToAddresses: [
40      /* more items */
41    ],
42  });
43};
44
45const run = async () => {
46  const sendEmailCommand = createSendEmailCommand(
47    "recipient@example.com",
48    "sender@example.com",
49  );
50
51  try {
52    return await sesClient.send(sendEmailCommand);
53  } catch (e) {
54    console.error("Failed to send email.");
55    return e;
56  }
57};
58
59run();
aws_ses_v3_send_html_text_email_typescript.ts - Raysurfer Public Snippets