Email webhooks: track delivery, bounces and opens in real time
How email webhooks work, which events to handle, and how to verify signatures so nobody can forge them.
An email API tells you a message was accepted. Webhooks tell you what happened next — delivered, bounced, opened, clicked, or marked as spam.
Events Stack Emails sends
| Event | When it fires |
|---|---|
email.sent |
Accepted by the mail provider |
email.delivered |
Accepted by the recipient's mail server |
email.delivery_delayed |
Temporary failure, still retrying |
email.bounced |
Permanently rejected |
email.complained |
Recipient reported spam |
email.opened / email.clicked |
Engagement (if tracking is enabled) |
email.received |
Inbound message arrived |
contact.*, domain.* |
Audience and domain changes |
Payload shape
{
"id": "evt_3kq...",
"type": "email.delivered",
"created_at": "2026-10-07T09:12:44.000Z",
"data": {
"email_id": "msg_8f2b...",
"to": ["ada@example.com"],
"subject": "Your receipt"
}
}
Verify the signature
Anyone who discovers your endpoint URL could post fake events to it. Every Stack Emails webhook is signed with your workspace's webhook secret:
X-StackEmails-Signature-V2: t=1760000000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
The signature is an HMAC-SHA256 of ${t}.${rawBody}. Including the timestamp stops attackers replaying an old, genuine event. Use the SDK helper:
// app/api/webhooks/email/route.ts
import { verifyWebhook } from "stackemails";
export async function POST(req: Request) {
const raw = await req.text(); // the raw body, not parsed JSON
const ok = await verifyWebhook(raw, req.headers.get("x-stackemails-signature-v2"), process.env.STACKEMAILS_WEBHOOK_SECRET!);
if (!ok) return new Response("invalid signature", { status: 401 });
const event = JSON.parse(raw);
// ...handle event.type
return new Response("ok");
}
Always verify against the raw body — re-serialising parsed JSON changes whitespace and breaks the signature.
Handle retries and duplicates
If your endpoint returns anything other than a 2xx within 10 seconds, Stack Emails retries with backoff — after 30 seconds, 2 minutes, 10 minutes, 1 hour and 6 hours. That means you may occasionally receive the same event twice, so:
- Respond quickly and do heavy work in a background job.
- Deduplicate on the event
id(also sent as theX-StackEmails-Event-Idheader). - Use the delivery log under Webhooks to inspect payloads and redeliver manually.
With signed, retried webhooks, your app always knows the true state of every email.
Enjoyed this article?
See more from Stack Emails in Google Search.