Tuesday, 21 January 2025

AWS SES : Simple Email Service

 


AWS SES : Simple Email Service

1. Download access key and secret key excel file.

2. Go to verified identity -> Create Identity -> Verify email received in email account and verified.

3. npm install aws-sdk

const AWS = require("aws-sdk");

const awsConfig = {
  accessKeyId: AWS_ACCESS_KEY_ID,
  secretAccessKey: AWS_SECRET_ACCESS_KEY,
  region: process. AWS_REGION,
};

const SES = new AWS.SES(awsConfig);

const sendEmail = async () => {

  try {
    //prepare email to send

    const params = {
      Source: "verifiedemailaddress@gmail.com"  //verified email address
      Destination: {
        ToAddresses: "to@gmail.com",
      },
      Message: {
        Subject: {
          Charset: "UTF-8",
          Data: "OTP Verification",
        },
        Body: {
          Html: {
            Charset: "UTF-8",
            Data: `<h1>Your verification code is 12345</h1>`,
          },
        },
      },
    };

    const emailSent = SES.sendEmail(params).promise();
    emailSent
      .then((data) => {
        console.log(data);
      })
      .catch((err) => {
        console.log(err);
      });
  } catch (error) {
    console.log(error);
  }
};

module.exports = sendEmail;

No comments:

Post a Comment