Handling Bounces and Complaints in Amazon SES With SNS
Amazon SES bounce handling with SNS means attaching an Amazon SNS topic to your verified identity (or account) so SES publishes a JSON event every time a message bounces or a recipient marks it as spam, then consuming those events from a queue and writing the affected addresses to a suppression store. This article walks through the full pipeline: creating the topic and queue, pointing SES at them, parsing the payload, processing it idempotently in Node.js, and testing without damaging your sending reputation.
What SES Sends You, and Why SNS Is the Transport
SES does not push bounce and complaint data to your application directly. It publishes events to an SNS topic you nominate, either per verified identity or at the account level. There are two notification types you care about here:
- Bounce — the receiving mail server rejected the message. The fields that matter are
bounce.bounceType(Permanent,Transient,Undetermined),bounce.bounceSubType, and the list inbounce.bouncedRecipients[].emailAddress. - Complaint — the recipient marked the message as spam through their mail client. The fields are
complaint.complaintFeedbackTypeandcomplaint.complainedRecipients[].emailAddress.
Both event types carry mail.messageId (correlate back to the send), mail.destination (the envelope recipients), and a timestamp. SNS can deliver to HTTPS endpoints, SQS queues, Lambda, or email. For a durable pipeline, SQS is the pragmatic default: SNS retries failed deliveries, the queue buffers spikes, and you can replay messages after a bug fix. A raw HTTPS endpoint works, but you then own retry logic and must verify the SNS message signature yourself.
SES also offers event destinations that publish to other AWS services, which is worth knowing about if you already have that infrastructure. SNS remains the classic path and the one this article covers end to end. AWS documents the event schema in its developer guide; check the current field list there before you build parsing logic, since the schema has grown over time.
Prerequisites
Before writing any code, confirm you have:
- An AWS account with SES access in the region you intend to send from.
- A verified sending identity — a domain (with DKIM) or a single verified email address.
- AWS CLI v2 installed and configured (
aws configure) with credentials that can create SNS topics, SQS queues, IAM policies, and call SES. - Node.js 20 or later. All code below uses the AWS SDK v3 (
@aws-sdk/client-sqs,@aws-sdk/client-sns,@aws-sdk/client-sesv2). - Permission to move SES out of the sandbox. In sandbox mode you can only send to verified recipients, which makes realistic testing awkward. You request production access from the SES console; check the current sandbox limits there, as they change.
Create the SNS Topic and Subscribe a Queue
Create the topic and queue, then subscribe the queue to the topic.
aws sns create-topic --name ses-bounce-complaint
# note the TopicArn in the output
aws sqs create-queue --queue-name ses-events
# note the QueueUrl
aws sqs get-queue-attributes \
--queue-url <QUEUE_URL> \
--attribute-names QueueArn
aws sns subscribe \
--topic-arn <TOPIC_ARN> \
--protocol sqs \
--notification-endpoint <QUEUE_ARN>
The subscription is created immediately for SQS (unlike HTTPS, which requires confirming the subscription). Now grant SNS permission to write to the queue. Save this as queue-policy.json, replacing the ARNs:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "sns.amazonaws.com" },
"Action": "sqs:SendMessage",
"Resource": "<QUEUE_ARN>",
"Condition": {
"ArnEquals": { "aws:SourceArn": "<TOPIC_ARN>" }
}
}
]
}
Apply it:
aws sqs set-queue-attributes \
--queue-url <QUEUE_URL> \
--attributes Policy="$(cat queue-policy.json)"
Putting a queue in front of your handler buys you three things: SNS retries deliveries to the queue, the queue absorbs bursts, and you can replay messages. It also introduces at-least-once delivery — the same event can arrive twice — which is why idempotency matters later.
Point SES at the Topic
You can attach a topic per identity or at the account level. Per identity:
aws sesv2 create-email-identity --email-identity example.com # if not already verified
aws ses set-identity-notification-topic \
--identity example.com \
--notification-type Bounce \
--sns-topic <TOPIC_ARN>
aws ses set-identity-notification-topic \
--identity example.com \
--notification-type Complaint \
--sns-topic <TOPIC_ARN>
You can use separate topics for bounces and complaints if you want different consumers. Account-level settings apply when an identity has no override, which is convenient when you add new domains. After configuring, open the SES console and confirm the topic ARN is attached to the identity — a typo in the ARN is the most common reason events never arrive.
The Event Payload, Field by Field
Here is an illustrative permanent bounce, wrapped in the SNS envelope as it arrives from SQS:
{
"Type": "Notification",
"MessageId": "8a3f2c1e-...",
"TopicArn": "arn:aws:sns:eu-west-1:123456789012:ses-bounce-complaint",
"Message": "{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceType\":\"Permanent\",\"bounceSubType\":\"General\",\"bouncedRecipients\":[{\"emailAddress\":\"user@example.net\",\"action\":\"failed\",\"status\":\"550\",\"diagnosticCode\":\"smtp; 550 5.1.1 user unknown\"}],\"timestamp\":\"2026-11-24T10:12:03.000Z\"},\"mail\":{\"messageId\":\"0100018f...\",\"destination\":[\"user@example.net\"]}}"
}
The Message field is a JSON string, so you parse it twice. Decisions hinge on bounceType:
- Permanent — the mailbox does not exist or is permanently unreachable. Suppress the address.
- Transient — a temporary failure such as a full mailbox or a greylisting delay. Do not suppress immediately; SES retries transient bounces internally. A
bounceSubTypeofSuppressedmeans SES itself already blocked the send because the address is on the account suppression list. - Undetermined — ambiguous. Treat conservatively and watch the address.
A complaint payload looks similar but carries complaint.complaintFeedbackType (values include abuse, auth-failure, fraud, not-spam, other, virus). A complaint means a real person clicked "mark as spam." Suppress the address and treat it as a signal about content or list hygiene, not just a data point.
Processing Events: A Runnable Handler
This handler long-polls SQS, parses the envelope, branches on notificationType, and writes to a suppression store. The store here is an in-memory Set for illustration only — use DynamoDB or Postgres in production.
// handler.mjs
import { SQSClient, ReceiveMessageCommand, DeleteMessageCommand } from "@aws-sdk/client-sqs";
const sqs = new SQSClient({ region: process.env.AWS_REGION });
const QUEUE_URL = process.env.QUEUE_URL;
// Illustrative only. Replace with a durable store.
const suppression = new Set();
function extractSuppressions(event) {
const addresses = [];
if (event.notificationType === "Bounce") {
const type = event.bounce?.bounceType;
if (type === "Permanent") {
for (const r of event.bounce.bouncedRecipients ?? []) {
addresses.push({ email: r.emailAddress, reason: "bounce_permanent" });
}
}
} else if (event.notificationType === "Complaint") {
for (const r of event.complaint?.complainedRecipients ?? []) {
addresses.push({ email: r.emailAddress, reason: "complaint" });
}
}
return addresses;
}
async function processMessage(body) {
const envelope = JSON.parse(body);
const event = JSON.parse(envelope.Message);
const found = extractSuppressions(event);
for (const { email, reason } of found) {
suppression.add(email);
console.log(`suppressed ${email} (${reason}) messageId=${event.mail?.messageId}`);
}
}
async function main() {
while (true) {
const res = await sqs.send(new ReceiveMessageCommand({
QueueUrl: QUEUE_URL,
MaxNumberOfMessages: 10,
WaitTimeSeconds: 20,
VisibilityTimeout: 30,
}));
for (const msg of res.Messages ?? []) {
try {
await processMessage(msg.Body);
await sqs.send(new DeleteMessageCommand({
QueueUrl: QUEUE_URL,
ReceiptHandle: msg.ReceiptHandle,
}));
} catch (err) {
// Do NOT delete: let SQS redeliver, then route to the DLQ.
console.error("processing failed", err);
}
}
}
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
The critical line is the one you do not write: on failure, the message is not deleted, so SQS redelivers it after the visibility timeout. Configure a dead-letter queue with a maxReceiveCount (for example, 5) so poison messages do not loop forever. If you deliver to HTTPS instead of SQS, you must verify the SNS message signature before trusting the payload — that is a separate code path AWS documents in detail.
Idempotency and Retries
SNS-to-SQS is at-least-once, and SES can emit more than one event for the same message, so your handler will see duplicates. Use the SNS MessageId (or a hash of MessageId plus recipient) as an idempotency key with a conditional write:
import { DynamoDBClient, PutItemCommand } from "@aws-sdk/client-dynamodb";
const ddb = new DynamoDBClient({ region: process.env.AWS_REGION });
async function suppressOnce(email, messageId, reason) {
try {
await ddb.send(new PutItemCommand({
TableName: "suppressions",
Item: {
email: { S: email },
messageId: { S: messageId },
reason: { S: reason },
},
ConditionExpression: "attribute_not_exists(email) OR messageId <> :mid",
ExpressionAttributeValues: { ":mid": { S: messageId } },
}));
return true;
} catch (err) {
if (err.name === "ConditionalCheckFailedException") return false; // already processed
throw err;
}
}
On the retry side: set a visibility timeout comfortably longer than your worst-case processing time, cap redeliveries with maxReceiveCount, and route overflow to a DLQ you actually monitor. For HTTPS endpoints, SNS has its own retry policy you can tune. And remember the SES-side behavior: transient bounces are retried internally, so suppressing on them immediately throws away addresses that would have delivered on the next attempt.
Testing Without Burning Your Reputation
SES provides mailbox simulator addresses that generate real events without touching real inboxes. Send to bounce@simulator.amazonses.com, complaint@simulator.amazonses.com, and success@simulator.amazonses.com to exercise each path. Confirm the current simulator addresses in the SES docs, then send:
aws sesv2 send-email \
--from-email-address sender@example.com \
--destination ToAddresses=bounce@simulator.amazonses.com \
--content '{"Simple":{"Subject":{"Data":"test"},"Body":{"Text":{"Data":"test"}}}}'
Then check the queue:
aws sqs receive-message --queue-url <QUEUE_URL> --wait-time-seconds 10
To test the handler in isolation, publish a synthetic SNS message directly to the topic and confirm your code processes it. This lets you iterate on parsing logic without sending mail at all.
Going to Production: Suppression, Monitoring and Limits
Three things keep this pipeline healthy. First, keep your suppression list in sync with SES's account-level suppression list — SES can add addresses automatically, and you should mirror that state in your own store so your application checks one source of truth. Check the current behavior in the SES docs, since it has evolved.
Second, monitor bounce and complaint rates in CloudWatch. High rates can lead to your sending being paused, so treat the metrics as an early warning rather than a postmortem. AWS documents the reputation metrics and the consequences; read the thresholds there rather than hard-coding numbers that may change.
Third, understand the shared responsibility: SES provides the transport and the event stream, but you own the suppression logic and the decision about what to do with each event. If you would rather not build and maintain this pipeline yourself, Mailerflow handles automatic suppression of bounces and complaints, reputation monitoring and warm-up limits as part of its sending setup, alongside a transactional email API on a high-priority lane.
Troubleshooting
- Events never arrive. Check that the topic ARN is attached to the correct identity in the correct region, that the queue policy allows
sns.amazonaws.comto send, and that the SQS subscription exists. For HTTPS, confirm the subscription was accepted. - Duplicate processing. You are missing an idempotency key. Add the conditional write shown above.
- Events lost after a handler crash. You are deleting messages before processing succeeds. Delete only after success.
- Good addresses suppressed. You are acting on
Transientbounces. Restrict suppression toPermanentand complaints. - Signature verification failures on HTTPS. You are validating the wrong string or using a stale signing certificate. Follow the AWS verification steps exactly, or switch to SQS delivery and skip the problem.
FAQ
Do I need SNS, or can I use event destinations? SNS is the classic path for bounce and complaint notifications. Event destinations publish to other AWS services and are useful if you already run that infrastructure. Both are documented by AWS; pick based on where your consumers live.
What is the difference between a bounce and a complaint? A bounce is a delivery failure at the receiving server. A complaint is the recipient marking your message as spam. Both should suppress the address, but a complaint also signals a content or list-quality problem.
Should I suppress on Transient bounces? No, not immediately. SES retries transient failures internally. Suppress on Permanent bounces and complaints.
How do I avoid processing the same event twice? Use the SNS MessageId as an idempotency key with a conditional write in your suppression store.
Can I test without sending to real addresses? Yes — the SES mailbox simulator addresses generate real bounce and complaint events without harming your reputation.
Where This Fits in the SES Operations Cluster
This is the pillar article for the SES Operations cluster. Supporting pieces will go deeper on individual steps: building and syncing a suppression list, monitoring SES reputation with CloudWatch, and migrating from SES to a managed sender when the operational overhead stops being worth it. For a related topic you can read today, see our guide to Amazon SES configuration sets and event publishing, which covers the broader event model these notifications sit inside.
If you want to skip the queue-and-handler plumbing entirely, Mailerflow's transactional email API sends on a high-priority lane with templates, scoped keys, idempotency keys and automatic suppression of bounces and complaints. The developer docs include an OpenAPI spec and a JS SDK if you want to compare the two approaches side by side.


