ses_sendemail.ts - AWS Code Sample

ses_sendemail.ts

/* 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 AWS SDK for JavaScript version 3 (v3), which is pending release. The preview version of the SDK 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.ts demonstrates how to send an email using Amazon SES. Inputs (replace in code): - REGION - RECEIVER_ADDRESS - SENDER_ADDRESS Running the code: ts-node ses_sendemail.ts */ // Create the promise and SES service object // Import required AWS SDK clients and commands for Node.js const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses"); // Set the AWS Region const REGION = "REGION"; //e.g. "us-east-1" // Set the parameters const params = { Destination: { /* required */ CcAddresses: [ /* more items */ ], ToAddresses: [ "RECEIVER_ADDRESS", //RECEIVER_ADDRESS /* 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: "SENDER_ADDRESS", // SENDER_ADDRESS ReplyToAddresses: [ /* more items */ ], }; // Create SES service object const ses = new SESClient(REGION); const run = async () => { try { const data = await ses.send(new SendEmailCommand(params)); console.log("Success", data); } catch (err) { console.log("Error", err); } }; run();