Indie Kit DocsIndie Kit Docs

Amazon SES Setup

Learn how to set up Amazon SES with proper DNS records for reliable email delivery

Setting Up Amazon SES 📧

This guide will help you set up Amazon Simple Email Service (SES) with proper DNS records to ensure reliable email delivery and prevent your emails from being marked as spam.

Prerequisites 📋

  1. An AWS account
  2. Access to your domain's DNS settings
  3. Domain verified in AWS SES
  4. A production SES account (out of sandbox)

Domain Verification 🔍

  1. Go to AWS SES Console
  2. Click "Verified Identities" > "Create Identity"
  3. Choose "Domain" and enter your domain name
  4. Important: Use AWS-provided DKIM, DMARC, and SPF records
  5. Copy the DNS records from AWS dashboard
  6. Add them to your domain's DNS settings

Requesting Production Access 🚀

When applying for production access, use this template:

Use Case Description:
I am developing a SaaS platform that requires email functionality for essential user communications. Our email sending will be strictly limited to registered and verified users only. Key email use cases include:

1. User Authentication & Security
   - Account verification emails
   - Password reset notifications
   - Security alerts

2. User Engagement
   - Waitlist notifications
   - Welcome emails
   - Product updates
   - Service notifications

3. Email Management
   - We have implemented proper bounce and complaint handling
   - All recipients are verified users who have explicitly opted in
   - Unsubscribe links are included in all marketing communications
   - We follow email best practices and maintain clean recipient lists

4. Security Measures
   - DMARC, SPF, and DKIM are properly configured
   - Regular monitoring of bounce rates and complaints
   - Immediate removal of hard bounces
   - Compliance with anti-spam regulations

Implementation 💻

Install required dependencies:

pnpm add @aws-sdk/client-ses

Create src/lib/email/sendMail.ts:

import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";
import { appConfig } from "../config";
 
const sendMail = async (to: string, subject: string, html: string) => {
  if (process.env.NODE_ENV !== "production") {
    console.log(
      "Sending email to",
      to,
      "with subject",
      subject,
      "and html",
      html
    );
    return;
  }
 
  const ses = new SESClient({
    region: process.env.AWS_SES_REGION!,
    credentials: {
      accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
      secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
    },
  });
 
  const command = new SendEmailCommand({
    Destination: {
      ToAddresses: [to],
    },
    Message: {
      Body: {
        Html: {
          Data: html,
        },
      },
      Subject: {
        Data: subject,
      },
    },
    Source: `${appConfig.email.senderName} <${appConfig.email.senderEmail}>`,
    ReplyToAddresses: [appConfig.email.senderEmail],
  });
 
  const response = await ses.send(command);
  console.log("Email sent successfully", response);
};
 
export default sendMail;

Environment Variables 🔐

Add these to your .env.local:

AWS_SES_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key

Testing Email Setup 🧪

  1. Send a test email using AWS SES console
  2. Check email headers for proper DKIM alignment
  3. Use AWS SES dashboard to track bounces and complaints

Important Notes ⚠️

  1. DNS propagation takes time (24-48 hours)
  2. Start in SES sandbox for testing
  3. Request production access before sending bulk emails
  4. Keep bounce rate below 5%
  5. Monitor email reputation regularly

Remember to wait for DNS propagation before testing your email setup. Rushing this process can lead to delivery issues! 🚀

On this page