Skip to main content
Follow these best practices to build reliable, secure, and maintainable inbound email processing systems.

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’s Message-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 in content.email_rfc822. Parse it with a MIME library in your background job, and store the files yourself if you need them later:
See Attachments for more on parsing attachments.

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

  • 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
  • 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
  • Verify the X-MessageSystems-Webhook-Token auth token
  • Validate and sanitize all inputs
  • Validate attachment types from content
  • Implement rate limiting
  • Scan attachments for malware
  • Monitor processing metrics
  • Set up alerts for anomalies
  • Log all processing for debugging
  • Plan for handling failures
  • Document your email routing rules

Setup

Configure inbound email

Security

Security best practices

Webhooks

Webhook configuration

Sending Best Practices

Best practices for sending