Email Processing Pipeline
When an email arrives at a ServerlessInbox domain it passes through a chain of AWS services before it lands in a user’s mailbox. This page explains that chain and the design choices behind it.
Scope: This page covers inbound email receiving only. Outbound sending and its feedback loop (bounces, complaints, delivery notifications) are covered separately.
Infrastructure overview
Section titled “Infrastructure overview”The receiving path is built on AWS services acting as a reliable pipeline: SES → S3 and a forwarder function → SQS → Lambda.
graph LR Internet["Internet (SMTP)"] SES["Amazon SES<br/>Receipt Rules"] S3_raw["S3<br/>incoming-emails/"] Forwarder["Lambda<br/>receipt forwarder"] SQS["SQS Queue"] Lambda["Lambda<br/>email-processor"]
Internet -->|"SMTP (TLS required)"| SES SES -->|"1. Store raw MIME"| S3_raw SES -->|"2. Notify"| Forwarder Forwarder -->|"Enqueue notification"| SQS SQS --> LambdaSES first writes the full email to S3, then publishes a lightweight notification — so the raw message is always durably stored before any processing begins.
The forwarder between SES and SQS
Section titled “The forwarder between SES and SQS”SES receipt rules cannot publish to SQS directly, and their SNS notification action limits the size of the inbound message it can carry. A small forwarder function receives the notification from SES and places it on the queue, so every message takes the same path whatever its size. Full-text search indexing does not hang off inbound mail events; it runs independently on an EventBridge schedule, see Search Architecture.
Reliability
Section titled “Reliability”| Concern | Mechanism |
|---|---|
| Temporary failures | The message is retried automatically |
| Unknown or inactive recipients | A final outcome: processed once, recorded in the Mail log, never retried |
| Partial batch failures | Only failed messages in a batch are retried, not the whole batch |
| Data loss on cold start | Raw MIME is in S3 before Lambda is ever invoked |
What the processor does
Section titled “What the processor does”The Lambda receives a batch of notifications and processes each one independently:
graph TD A["Notification arrives"] B["Identify recipients<br/>(alias, then catch-all)"] C["Download MIME from S3"] D["For each routed recipient:<br/>route to inbox or junk"] E["Store email<br/>(S3 + DynamoDB)"] G["Record outcomes<br/>(Mail log)"] F["Notify connected clients<br/>(WebSocket push)"]
A --> B --> C --> D --> E --> G --> FIdentifying recipients
Section titled “Identifying recipients”SES delivers email to an entire domain — it does not know which tenant or account owns a given address. The processor resolves each destination address by looking it up in the database.
A few things happen during this lookup:
- Plus-addressing —
user+tag@domain.comis treated asuser@domain.comfor delivery purposes. - Alias resolution — every address is an alias pointing to an account. An exact alias match always decides the delivery.
- Catch-all — an address with no alias is checked against the catch-all of its domain. If the domain has one, the mail goes to the catch-all account.
- Deduplication — if multiple envelope addresses resolve to the same account, only one copy of the email is stored.
Because SES hands the processor a whole domain’s mail, address resolution is deliberately the processor’s job rather than something pushed into the SES receipt rule: aliases, plus-addressing and account ownership are product concepts that change far more often than infrastructure should. Keeping them in one place means a mailbox or alias change takes effect immediately, with no SES rule update and no redeploy.
The effect is what you would expect: mail addressed to your domain is delivered to the mailboxes it is addressed to, with aliases and plus-addressed variants arriving in the account that owns them.
Each recipient of a message is handled on its own, so one address never holds up another. Up to 200 recipients of one message are routed; recipients beyond that are not delivered.
| Situation | Result |
|---|---|
| Active alias | Delivered to the alias’s account |
| No alias, and the domain has a catch-all account | Delivered to the catch-all account |
| No alias, and no usable catch-all | Not delivered; recorded as an unknown recipient |
| Alias exists but is inactive | Not delivered, and never passed on to the catch-all; recorded as an inactive alias |
| The account has no inbox (for a junk message: no junk folder and no inbox) | Not delivered; recorded as a failed delivery |
| A temporary platform failure while resolving or storing | The message is received again and retried |
The unknown-recipient, inactive-alias and no-inbox outcomes are final: the message is processed once and is not retried, because a retry cannot change the result. A temporary failure is different. The message stays queued and is retried automatically (see Reliability), and the other recipients of the message are still delivered. Every outcome is recorded in the Mail log. Mail addressed to a domain that no tenant owns is not recorded.
Routing to inbox or junk
Section titled “Routing to inbox or junk”Once recipients are resolved, SES’s scanning verdicts determine where the email lands:
- Spam detected → placed in the junk mailbox (or inbox with the junk flag if no junk mailbox is configured), per RFC 8621 §9.
- Malware detected → filed to junk as well, by the same route and with the same flag behaviour.
- DMARC failure under a
quarantineorrejectpolicy → filed to junk by the same route. A failure under a policy ofnonegoes to the inbox. - Everything else → inbox.
Junk is the right destination for a suspect message rather than silent deletion: the recipient can see that something arrived and was set aside. The message is kept away from the inbox without a decision being made on the user’s behalf that they never get to review.
SES performs the scanning itself, at the edge, before a message ever reaches our code. See Spam & Phishing Protection for what is filtered and how to handle filtered mail.
Storing the email
Section titled “Storing the email”Each recipient gets their own copy of the email stored in per-account S3 storage, plus a record in
DynamoDB. Mailbox unread counters are updated atomically. After all recipients are processed, the
original raw object in the incoming-emails/ S3 prefix is deleted as a best-effort cleanup.
Notifying connected clients
Section titled “Notifying connected clients”At the end of the batch, any accumulated change notifications are pushed to connected JMAP clients via WebSocket. This is what makes new mail appear in the UI without a page refresh.
Related topics
Section titled “Related topics”- System Architecture — how the email-processor fits into the broader platform.
- Bounce & Complaint Handling — what happens after an outbound email is sent.
- Trust & Code Integrity — code signing and trust boundaries between the control plane and data plane.