Skip to content
Go back

Setting Up AWS SES for Transactional Emails

Setting Up AWS SES for Transactional Emails

Introduction

Amazon SES provides a scalable solution for sending transactional emails. This guide covers domain verification, SMTP and API integration, and best practices.

Prerequisites

Step 1: Verify Domain

In SES console:

  1. Navigate to Domains > Verify a New Domain.
  2. Add DNS TXT record for verification.
  3. Enable DKIM by adding CNAME records.

Step 2: Configure Sending Limits

Request production access to raise sending limits.

Step 3: Sending via SMTP

Create SMTP credentials:

aws ses create-smtp-credentials --user-name ses-smtp-user

Use nodemailer in Node.js:

npm install nodemailer aws-sdk
import nodemailer from 'nodemailer';
import AWS from 'aws-sdk';

AWS.config.update({ region: 'us-east-1' });

// Create SES transporter
const transporter = nodemailer.createTransport({
  SES: new AWS.SES({ apiVersion: '2010-12-01' }),
});

export async function sendEmail(to, subject, html) {
  const params = {
    Destination: { ToAddresses: [to] },
    Message: {
      Body: { Html: { Charset: 'UTF-8', Data: html } },
      Subject: { Charset: 'UTF-8', Data: subject },
    },
    Source: 'no-reply@yourdomain.com',
  };

  return transporter.sendMail({
    from: params.Source,
    to,
    subject,
    html,
  });
}

Step 4: Sending via API

npm install @aws-sdk/client-ses
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses';

const client = new SESClient({ region: 'us-east-1' });

export async function sendEmailAPI(to: string, subject: string, html: string) {
  const command = new SendEmailCommand({
    Destination: { ToAddresses: [to] },
    Message: {
      Body: { Html: { Charset: 'UTF-8', Data: html } },
      Subject: { Charset: 'UTF-8', Data: subject },
    },
    Source: 'no-reply@yourdomain.com',
  });

  return client.send(command);
}

Step 5: Best Practices

Summary

AWS SES offers both SMTP and direct API methods to send transactional emails reliably and cost-effectively. Verify domains, configure credentials, and follow email best practices to ensure deliverability.


Share this post on:

Previous Post
Orchestrating Workflows with AWS Step Functions
Next Post
Using AWS ECS for Containerized Applications