Products · Delivery V1

Email delivery

Get the files immediately by secure download, with a copy by email.

Version 1 · Email through ResendDesigned, not builtModule 8 of 15

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

  1. Payment. Marks the order paid from Stripe's verified event and tells DocFlow.
  2. DocFlow's server. Calls POST /messages with the user, order_paid, the document name, amount and the success page's path, keyed by the payment event's ID.
  3. Delivery. Records the message queued and answers at once.
  4. Delivery. Looks up the user's verified address through Identity, renders the template and sends it through Resend from receipts@01scale.com.
  5. Resend. Accepts the email for delivery, signed for SPF and DKIM.
  6. Delivery. Marks it sent; or after 3 failed retries failed, and announces delivery.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_service role
RESEND_API_KEYsecret
The Resend API key
EMAIL_FROM
DocFlow <receipts@01scale.com>, on a domain verified in Resend
IDENTITY_API_URL
Where Delivery looks up a user's verified email
IDENTITY_JWKS_URL
https://01scale.com/api/identity/v1/jwks
EVENTS_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 scope identity: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?