Bounces and complaints
Make an email bounce or be marked as spam, by hand or with a magic address, and send the event to your app in your provider's format.
Try it in the demo.
The situation: your app should stop emailing addresses that bounce and people who mark it as spam, and maybe show "email bounced" to an admin. Real bounces are hard to produce, so this code is rarely tested.
You need: your app's mail settings pointing at SendMock, and your app's bounce webhook handler URL.
Steps
- Send the event to your app. In Webhooks > Endpoints, press Add endpoint, set your handler's URL, and in Request pick your provider's event template (for example "SendGrid: Event Webhook"). Then in Webhooks > Rules, add a rule for that endpoint with the events
email.bouncedandemail.complained. - Bounce by address. In your app, send an email to
[email protected]. It hard bounces by itself (550 5.1.1 user unknown).[email protected]is delivered and then marked as spam. - Or bounce by hand. Open any email in Mail, press Simulate and pick Hard bounce, Soft bounce or Spam complaint.
- Open Webhooks > Deliveries: the event was posted to your handler, and your app's answer is there.
Which addresses do what
delivered@, bounce@, bounce+hard@, bounce+soft@ and complaint@ work on any domain; the Amazon SES simulator addresses work too. The full table is on Outcomes. Test an address in Settings > Email tells you what an address will do.
In your code
A test that makes an invitation bounce and checks the bounce reached your app's webhook.
The examples call SendMock's REST API with each language's usual HTTP client and test framework. JavaScript, Go, Java, Rust, Ruby and C# use the small call helper shown under Test helper on their page in Connect your app.
# In your app: invite [email protected]
email=$(sendmock email wait --to [email protected] --timeout 10s --json)
sendmock email simulate "$(jq -r '.id' <<<"$email")" bounced --bounce-type hard
delivery=$(sendmock webhook deliveries wait --event email.bounced --timeout 10s --json)
jq -e '.status == "succeeded"' <<<"$delivery" >/dev/nullWhat you should see
The email with a Bounced or Complained badge and a Timeline entry, a delivery in Deliveries, and your app marking the address as suppressed.
Try it in the demo
- In Settings > Email, type
[email protected]in Test an address: it says "Magic address: Hard bounce (550 5.1.1)". - Open Mail, click Reset your password, press Simulate and pick Hard bounce.
- The Timeline tab lists the bounce.
Next
- Advanced: email outcome addresses: your own addresses that always bounce.
- Outcomes