# Bounce and complaint handling

When your email provider reports that a newsletter hard-bounced or that a reader marked it as spam, Perspect stops sending newsletters to that address. This protects your sending domain's reputation, and it is something Gmail and Yahoo expect of bulk senders.

## What Perspect does with each event

| Event | What changes |
| --- | --- |
| Hard (permanent) bounce | The subscription becomes **bounced** and gets no further campaigns. |
| Spam complaint | The subscription becomes **complained** and gets no further campaigns. |
| Soft (temporary) bounce | Nothing. The provider retries on its own. |

Events only change subscriptions on the site they were sent for. Addresses that aren't subscribers are ignored.

Every campaign also carries a one-click **List-Unsubscribe** header, so readers can unsubscribe from their mail client without ever reaching a spam complaint.

## Where events are sent

Each site receives provider events at its own address:

```
https://<your site's domain>/_newsletter/email-events
```

Perspect uses your site's custom domain when it has one, and its Perspect subdomain otherwise. The exact URL is shown under **Email Settings → Bounces and complaints**. Your provider sees your domain, never a Perspect hostname.

If your site runs on its own Cloudflare Worker rather than on Perspect hosting, that Worker has to forward these requests first. See [Newsletter routes on your own Worker](/docs/developers/newsletter-routes).

## Set it up

Configure your email provider in **Email Settings** first. Then follow the steps under **Bounces and complaints** for that provider.

### Resend

1. In Resend, open **Webhooks** and add an endpoint with the URL shown in Email Settings.
2. Select the `email.bounced` and `email.complained` events.
3. Copy the webhook's signing secret, paste it into Email Settings, and save.

### SendGrid

1. In SendGrid, open **Settings → Mail Settings → Event Webhook** and set the Post URL to the URL shown in Email Settings.
2. Select **Bounced** and **Spam Reports**, turn on **Signed Event Webhook**, and save.
3. Copy the verification key, paste it into Email Settings, and save.

### Mailgun

1. In Mailgun, open your sending domain's **Webhooks** and add the URL for **Permanent Failure** and **Spam Complaints**.
2. Copy the HTTP webhook signing key from the same page, paste it into Email Settings, and save.

### Amazon SES

SES reports events through an Amazon SNS topic.

**1. Create a topic and save its ARN.** In your SES region, create a standard SNS topic. Paste its ARN into Email Settings and save. Do this before subscribing, because Perspect only confirms subscriptions for the topic you saved.

```bash
aws sns create-topic --region us-east-1 --name my-site-ses-events
```

A topic in the same AWS account as SES needs nothing more: SES publishes to it with the account's own permissions. If the topic is in another account or encrypted with a customer-managed KMS key, give SES permission to publish to it as well (and, for KMS, to use the key):

```bash
aws sns set-topic-attributes --region us-east-1 --topic-arn <topic ARN> \
  --attribute-name Policy --attribute-value '{
    "Version": "2012-10-17",
    "Statement": [{
      "Effect": "Allow",
      "Principal": {"Service": "ses.amazonaws.com"},
      "Action": "sns:Publish",
      "Resource": "<topic ARN>",
      "Condition": {"StringEquals": {"AWS:SourceAccount": "<SES account ID>"}}
    }]
  }'
```

This replaces the topic's policy, so keep any statements it already has.

**2. Subscribe the events URL to the topic.** Perspect confirms the subscription automatically.

```bash
aws sns subscribe --region us-east-1 \
  --topic-arn <topic ARN> \
  --protocol https \
  --notification-endpoint https://<your site's domain>/_newsletter/email-events
```

Check that it was confirmed. `SubscriptionArn` should be a full ARN, not `PendingConfirmation`.

```bash
aws sns list-subscriptions-by-topic --region us-east-1 --topic-arn <topic ARN>
```

**3. Send SES bounces and complaints to the topic.** How you do this depends on whether anything else sends from the same SES identity (domain or address).

**If another app also sends from this identity, use a configuration set.** This is the common case, for example when your app sends its own receipts or password resets from the same domain. An identity has only one bounce topic and one complaint topic, and they cover all of its mail. A configuration set keeps Perspect's events separate:

```bash
aws sesv2 create-configuration-set --region us-east-1 \
  --configuration-set-name perspect-newsletters

aws sesv2 create-configuration-set-event-destination --region us-east-1 \
  --configuration-set-name perspect-newsletters \
  --event-destination-name perspect-events \
  --event-destination '{"Enabled":true,"MatchingEventTypes":["BOUNCE","COMPLAINT"],"SnsDestination":{"TopicArn":"<topic ARN>"}}'
```

Then, in **Email Settings → Edit Configuration**, enter `perspect-newsletters` under **Configuration Set**, re-enter your credentials, and save. Every email Perspect sends for the site uses that set, so only Perspect's bounces and complaints reach the site. Your other app's identity notifications stay as they are.

> **Don't change the identity's own notification topic** if another app relies on it. `aws ses set-identity-notification-topic` replaces that app's topic for the whole identity. To see what's set now, run `aws ses get-identity-notification-attributes --identities <your domain>`.

**If only Perspect sends from this identity,** you can skip the configuration set and point the identity itself at the topic:

```bash
for t in Bounce Complaint; do
  aws ses set-identity-notification-topic --region us-east-1 \
    --identity <your domain> --notification-type $t --sns-topic <topic ARN>
done
```

## Test it

Send a test email to the SES bounce simulator. In **Email Settings**, click **Send Test Email** and send it to:

```
bounce@simulator.amazonses.com
```

SES reports a hard bounce for that address. Within a minute, the provider should deliver the event to your events URL. Because the simulator isn't a subscriber, no subscription changes. To see a subscription switch to **bounced**, subscribe the simulator address to a list and send that list a campaign.

## Troubleshooting

| What you see | What it means |
| --- | --- |
| Email Settings says "This deployment has no public URL to receive provider events" | Perspect can't find a domain for the site that reaches it. For a site on its own Worker, the Worker isn't forwarding `/_newsletter/*` yet. |
| The SNS subscription stays `PendingConfirmation` | Save the topic ARN in Email Settings, then run `aws sns subscribe` again. SNS sends a new confirmation to a pending subscription. |
| Events from your other app's mail change newsletter subscribers | The identity's own notification topic points at Perspect. Use a configuration set (above) and restore the identity's original topic. |
