Email delivery
Get the files immediately by secure download, with a copy by email.
ProductRead MeSections
Read Me
Delivery is the platform service that sends messages to users on an app's behalf. In DocFlow it sends the email that confirms a payment and links back to the results.
An app's server names the user, a template and the template's values; Delivery looks up the user's verified address, fills the template, sends it through Resend and retries if sending fails. Apps never handle email addresses.
In this module the downloads themselves and the success page belong to the DocFlow app: it checks that the order is paid and hands out a 5-minute link to the file. Delivery's part is the email.
Why it exists
One way to reach a person
Every app sends through the same service, with the same templates, retries and records, and MVP2 adds SMS and push behind the same request.
Addresses stay in Identity
Apps pass a user ID, never an email address, so personal data is not copied around the platform.
Sent once, by the server
Emails are triggered by verified server events and an idempotency key, so a repeated event or a closed browser never duplicates or loses one.
Trustworthy mail
Fixed templates, links that can only point at 01scale.com, and a verified sending domain keep the email out of spam and out of phishing.
In this version
- Send the `order_paid` email, in plain text and HTML, through Resend
- Look up the verified address at send time
- Retry 3 times with backoff, then record the failure and announce it
- Show a person the status of their messages
- Cancel and delete a deleted account's messages
Not in this version
- The success page and secure downloads: the DocFlow app (
DOCFLOW-V1-E7-01,DOCFLOW-V1-E7-02), designed with the DocFlow app shell - SMS, push and notification preferences:
DELIVERY-V2-E14 - Marketing email: not planned
How an email is delivered
- Payment. Marks the order paid from Stripe's verified event and tells DocFlow.
- DocFlow's server. Calls
POST /messageswith the user,order_paid, the document name, amount and the success page's path, keyed by the payment event's ID. - Delivery. Records the message
queuedand answers at once. - Delivery. Looks up the user's verified address through Identity, renders the template and sends it through Resend from receipts@01scale.com.
- Resend. Accepts the email for delivery, signed for SPF and DKIM.
- Delivery. Marks it
sent; or after 3 failed retriesfailed, and announcesdelivery.message.failed.
Words used here
- Template
- A fixed email with named blanks. Version 1 has one:
order_paid. - Idempotency key
- A value that makes the same request send only one email, however often it is repeated.
- SPF and DKIM
- DNS records that let mailboxes verify an email really came from 01scale.com.
Quick start
These examples work once the service is built and deployed.
1. Send an email from an app's server
Name the user and the template; never an address.
await callService("/api/delivery/v1/messages", { onBehalfOf: userId }, {
template: "order_paid", reference: `docflow:${documentId}`,
data: { document_name: "invoice.pdf", amount: 500, currency: "USD", link_path: `/documents/${documentId}/success` },
}, { headers: { "Idempotency-Key": paymentEventId } });2. Show the email's status
On a page the person is looking at.
import { MessageStatus } from "@01scale/ui-delivery";
<MessageStatus reference={`docflow:${documentId}`} />Configuration
Environment variables on the service's own deployment. Secrets are never committed.
DELIVERY_DATABASE_URLsecret- Neon connection string for the
delivery_servicerole RESEND_API_KEYsecret- The Resend API key
EMAIL_FROMDocFlow <receipts@01scale.com>, on a domain verified in ResendIDENTITY_API_URL- Where Delivery looks up a user's verified email
IDENTITY_JWKS_URLhttps://01scale.com/api/identity/v1/jwksEVENTS_SIGNING_KEYsecret- 32 random bytes, base64
Open questions
- Decided by Nikhil on 20 Nov 2026 (#68): Delivery reads the verified address with Identity
GET /api/identity/v1/users/{userId}, a service-only endpoint that needs the scopeidentity:users.read. It is designed with Account management (IDENTITY-V1-E1-05, PR #70). The event that triggers an email never carries the address. - Resend can report bounces and complaints by webhook. Version 1 records only whether Resend accepted the email; should a later bounce mark it failed?