Prompt
I'm building a small SaaS and need email delivery webhooks.
Latest observation
Oct 2, 2026
Gemini
To track email delivery in a SaaS application, setting up webhooks keeps your database synchronized with the real-time status of sent emails.
Key Delivery Events to Track
| Event Type | Triggers When | Primary Action |
|---|---|---|
| delivered | Recipient server accepts the message | Mark email as successfully delivered. |
| bounced | Hard (permanent) or soft (temporary) rejection | Suppress recipient email or notify user. |
| complained | Recipient marks email as spam | Immediately unsubscribe and add to suppression list. |
| opened / clicked | Recipient opens email or clicks a link | Update engagement metrics. |
Core Architecture & Best Practices
┌─────────────────────┐ POST /webhooks/email ┌─────────────────────────┐
│ Provider (Resend, │ ─────────────────────────────────> │ Endpoint (Fast 200 OK) │
│ Postmark, SES, etc.)│ └────────────┬────────────┘
└─────────────────────┘ │
▼
┌─────────────────────────┐
│ Queue / Async Worker │
└────────────┬────────────┘
▼
┌─────────────────────────┐
│ DB Status Update │
└─────────────────────────┘
- Keep Handlers Fast: Always return an immediate
200 OK. Offload parsing, database updates, and side effects to an async background queue (e.g., Redis/BullMQ, Celery, SQS) to avoid timing out the provider's HTTP request. - Signature Verification: Always verify HMAC signatures using the provider’s shared secret/signing key to prevent unauthorized payload injections.
- Idempotency & Deduplication: Webhooks are delivered with at least once delivery semantics and may retry on failure. Store and check incoming
event_idormessage_idvalues before processing.