Email Sending Pipeline
When a user sends an email, the system separates the act of submitting the email from the act of delivering it. This keeps the JMAP API responsive and ensures delivery is retried reliably even if something fails after the user’s request completes.
Overview
Section titled “Overview”graph LR Client["JMAP client"] API["JMAP API<br/>EmailSubmission/set"] SQS["SQS Queue<br/>email-submissions"] DLQ["SQS DLQ<br/>(14 day retention)"] Lambda["Lambda<br/>email-sender"] SES["Amazon SES"] Internet["Recipient's<br/>mail server"]
Client -->|"POST /jmap"| API API -->|"enqueue"| SQS SQS -->|"max 5 retries"| DLQ SQS --> Lambda Lambda --> SES SES --> InternetThe JMAP API creates the submission record, enqueues it to SQS, and returns immediately. The
email-sender Lambda processes the queue independently.
Step 1 — The JMAP submission
Section titled “Step 1 — The JMAP submission”A client sends an email by calling EmailSubmission/set with a create operation. This requires
two things to already exist:
- An Email object in the Drafts mailbox (the MIME content, stored in S3)
- An Identity — the verified sending address to use as the
From
Before creating the submission record, the API checks the suppression
list synchronously for every envelope recipient. A
recipient is blocked by a hard-bounce suppression that has not expired, or by a complaint
suppression for the message’s class; soft bounces never block. If any recipient is blocked,
EmailSubmission/set rejects the call in the same response with a SetError of type
invalidRecipients that lists the blocked addresses, and records the attempt in the audit trail.
No submission record is created, nothing is enqueued, and no request reaches SES. If the lookup for
a recipient fails, the submission is refused rather than sent: an unchecked recipient is never sent
to. This happens entirely inside the JMAP API; the email-sender Lambda below never sees a
suppressed recipient.
Otherwise, the API creates a submission record that links the two, then enqueues it for sending.
Each recipient starts as queued (see Submission lifecycle).
The client can also provide:
- An
envelopeoverride to control the SMTPMAIL FROMandRCPT TOaddresses independently of the message headers
sendAt is set by the server to the time the submission was created; a create that supplies sendAt is refused with invalidProperties.
Every submission created through JMAP is handled as transactional mail; clients do not choose a message class.
Step 2 — What the sender Lambda does
Section titled “Step 2 — What the sender Lambda does”graph TD A["Submission arrives from SQS"] B["Fetch MIME from S3"] C["Validate identity &<br/>resolve envelope"] D["Apply user signature<br/>(server-side)"] E["Tag the message<br/>(SES tags)"] F["Send via SES"] G["Move Drafts → Sent"] H["Mark submission as sent"]
A --> B --> C --> D --> E --> F --> G --> HFetch MIME from S3
Section titled “Fetch MIME from S3”The message body is not stored in the SQS message — only the submission record is. The Lambda looks up the Email record to find its S3 key and downloads the content. This keeps queue messages small.
Apply signature server-side
Section titled “Apply signature server-side”If the user has a signature configured on the sending identity, it is injected into the MIME at send time — not at compose time. This means the draft in the user’s Drafts folder stays clean (no signature), and the outgoing message gets the current signature regardless of when the draft was written.
Text and HTML parts are each updated independently. For HTML, the signature is inserted before
</body> if present, or appended at the end.
Tag the message
Section titled “Tag the message”Before calling SES, the Lambda attaches metadata tags to the message:
| Tag | Purpose |
|---|---|
tenant_id | Routes feedback events back to the correct tenant |
submission_id | Links bounce/complaint/delivery events to this submission |
identity_id | Tracks which sending identity was used |
account_id / user_id | For audit and suppression records |
domain | The sending domain, for reputation analytics |
message_class | Scopes suppression list entries correctly |
These tags travel with the message through SES and appear on every feedback event (bounce, complaint, delivery). Without them, the system would not know which submission a bounce refers to.
Send via SES
Section titled “Send via SES”The full message is handed off to SES for delivery. This is what activates the feedback event pipeline — every bounce, complaint, and delivery notification flows back through the feedback pipeline.
Draft → Sent transition
Section titled “Draft → Sent transition”Immediately after a successful SES call, the Lambda moves the email from the Drafts mailbox to
the Sent mailbox and removes the $draft keyword. This is best-effort — if it fails, the email
was still sent, and the failure is logged rather than propagated.
Error handling
Section titled “Error handling”Not all SES errors are equal:
| Error type | Examples | Action |
|---|---|---|
| Retryable | Throttling, rate limits, 5xx server errors | Return error — SQS retries up to 5 times, then DLQ |
| Permanent | Invalid parameters, identity not verified, no envelope | Mark submission as failed; no retry |
Permanent failures write no as the delivery status of each recipient back to the submission record so the sender can see
what went wrong. The email remains in Drafts.
Submission lifecycle
Section titled “Submission lifecycle”A client reads the state of a send from the EmailSubmission. Its undoStatus is final for every send: the server offers no scheduled send and no cancelation.
Each recipient the client can see has a deliveryStatus entry, and its delivered value moves like this:
graph LR queued --> unknown queued --> no unknown --> yes unknown --> nodelivered | Meaning |
|---|---|
queued | The submission is created and waits to be sent |
unknown | SES accepted the message and has not yet reported an outcome, or reported a delay or a temporary failure |
yes | SES reported the message delivered to the recipient’s server |
no | The send failed permanently, SES rejected it, or the recipient bounced or reported a complaint |
The change from unknown to yes or no happens asynchronously via the
SES feedback pipeline. displayed is always unknown.
smtpReply has the form 250 2.0.0 text: a reply code, an enhanced status code and a text.
The EmailSubmission/set create answer carries the generated envelope and the initial deliveryStatus (every recipient queued), so a client shows the state without a further EmailSubmission/get.
There is no suppressed state here: a suppressed recipient is rejected synchronously by
EmailSubmission/set before a submission record exists, so it never enters this lifecycle at all
(see Step 1 above).
Related topics
Section titled “Related topics”- Bounce & Complaint Handling — how SES feedback events update submission status and protect sender reputation.
- Email Processing Pipeline — the inbound counterpart to this pipeline.
- Trust & Code Integrity — code signing and trust boundaries between the control plane and data plane.