Quick Response Pattern
The most critical rule for webhook handling: respond immediately, process asynchronously. Lettr waits up to 30 seconds for your endpoint to respond. If processing takes longer, the webhook is considered failed and will be retried.Idempotency
Webhooks may be delivered more than once due to retries, network issues, or edge cases. Your handler must be idempotent—processing the same event twice should have the same effect as processing it once.Using Event IDs
Every webhook event has a uniqueid. Store processed event IDs to detect and skip duplicates:
Database-Based Idempotency
For applications without Redis, use your database:Idempotency with Business Logic
Sometimes you need idempotency at the business level, not just event level:Queue-Based Processing
For high-volume applications or complex processing, use a message queue to decouple webhook receipt from processing:Error Handling
Proper error handling ensures you don’t lose events and can debug issues effectively.Categorizing Errors
Graceful Degradation
When external dependencies fail, don’t block the entire webhook:Relay Events and Inbound Email
Relay events (relay.relay_injection, relay.relay_delivery, relay.relay_rejection, relay.relay_tempfail, relay.relay_permfail) are status events about inbound email on your inbound domains. They tell you that a message was received, forwarded, rejected, or failed to reach your endpoint. They are not the inbound message itself and do not include its body or attachments.
The inbound message is posted to the Forwarding URL you set on the inbound domain, as a separate request with its own payload. Handle message content (routing by recipient, threading replies, extracting attachments from the raw MIME) in that endpoint, not in your webhook handler. See Email Parsing for the payload format and Email Routing and Reply Tracking for handler patterns.
In your webhook handler, treat relay events like any other status event, for example to alert when deliveries to your forwarding URL start failing:
Monitoring and Observability
Track webhook processing health with metrics and logging:Framework-Specific Examples
Next.js App Router
Express with TypeScript
Related Topics
Authorization
Secure your endpoints with authentication
Retries
Understand retry behavior and failure handling
Event Types
Complete reference of all webhook events
Testing
Test webhooks in development and production