Domain verification, SMTP or API integration, and what to watch out for with Amazon SES.
Prerequisites
- AWS account with SES permissions
- Verified domain or email
Step 1: Verify Domain
In SES console:
- Navigate to Domains > Verify a New Domain.
- Add DNS TXT record for verification.
- 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
- Use verified domains
- Monitor bounce and complaint rates via SNS
- Implement DKIM and SPF
SMTP via nodemailer for quick setup, the SDK API for more control. Either way, verify domains first and monitor bounces via SNS.