Architecture
Process Asynchronously
Respond to each delivery with a 2xx quickly and do slow work in the background. Lettr doesn’t document a timeout for your forwarding URL, so keep the request itself short:Implement Idempotency
The same message can arrive more than once, so make processing idempotent. Events carry no ID of their own; key on the message’sMessage-ID header instead:
Use Separate Queues by Priority
Reliability
Store Before Processing
Lettr doesn’t keep a copy of inbound mail, so save the payload yourself before any processing:Retry Your Own Downstream Calls
When your processing calls other services (your database, a ticketing API, storage), retry transient failures in your own code. This is your application’s retry policy, separate from how the message reaches your forwarding URL:Extract Attachments from the Raw Message
The payload has no attachment list or attachment URLs. Attachments are only inside the raw MIME message incontent.email_rfc822. Parse it with a MIME library in your background job, and store the files yourself if you need them later:
Error Handling
Graceful Degradation
Handle partial failures gracefully:Structured Error Logging
Performance
Batch Database Operations
Limit Concurrent Processing
Cache Common Lookups
Monitoring
Track Key Metrics
Set Up Alerts
Testing
Test Webhook Handling
Test Edge Cases
Checklist
Setup
Setup
- Configure inbound domain with MX records
- Set a forwarding URL on the domain and verify its auth token
- Decide how your handler treats spam (Lettr does not filter it)
- Set up monitoring and alerting
Processing
Processing
- Implement async processing (don’t block webhooks)
- Store raw emails before processing
- Implement idempotency (handle duplicates)
- Parse attachments from the raw MIME message
- Retry your own downstream calls on transient failures
Security
Security
- Verify the
X-MessageSystems-Webhook-Tokenauth token - Validate and sanitize all inputs
- Validate attachment types from content
- Implement rate limiting
- Scan attachments for malware
Operations
Operations
- Monitor processing metrics
- Set up alerts for anomalies
- Log all processing for debugging
- Plan for handling failures
- Document your email routing rules
Related Topics
Setup
Configure inbound email
Security
Security best practices
Webhooks
Webhook configuration
Sending Best Practices
Best practices for sending