Skip to content

Email Pipeline

Email pipeline

OwnerSaga (Seneschal)
Last reviewed2026-04-29 by Saga
Next review2026-07-29
Source paths.agents/skills/casaconomy-cloudflare/, .agents/skills/casaconomy-resend/, workers/licensing/src/lib/email.ts

What it is

The inbound and outbound email infrastructure for casaconomy.com. Inbound mail arrives via Cloudflare Email Routing and forwards to the regent’s Proton mailbox. Outbound mail (license keys, notifications) is sent through Resend’s API from the licensing Worker.

How it fits

Email is the “bannerstone” — the first external-facing service the keep raised, and the foundation that licensing and future user communication rest on. It sits entirely on the Cloudflare + Resend axis, requiring no additional providers.

flowchart LR
subgraph Inbound
Sender[External sender]
MX[CF Email Routing<br/>casaconomy.com MX]
Proton[Proton<br/>[email protected]]
Sender -->|SMTP| MX
MX -->|forward| Proton
end
subgraph Outbound
LicW[Licensing Worker<br/>licenses.casaconomy.com]
Resend[Resend API<br/>send.casaconomy.com]
Recipient[User inbox]
LicW -->|POST /emails| Resend
Resend -->|SMTP via SES| Recipient
end
subgraph DNS["Cloudflare DNS"]
SPF[SPF records]
DKIM[DKIM keys]
DMARC[DMARC policy]
end
MX -.->|validated by| SPF
Resend -.->|signs with| DKIM
Recipient -.->|checks| DMARC

Components

SourceResponsibility
.agents/skills/casaconomy-cloudflare/references/zone.mdCanonical DNS + Email Routing state (source of truth)
.agents/skills/casaconomy-cloudflare/scripts/cfOperator CLI for CF zone: MX records, routing rules, destinations
.agents/skills/casaconomy-resend/references/account.mdCanonical Resend state: domain, tokens, aliases
.agents/skills/casaconomy-resend/scripts/resendOperator CLI for Resend: send, verify domains, check delivery
workers/licensing/src/lib/email.tsProduction send functions: sendWelcomeEmail(), sendRevocationEmail()
workers/licensing/src/handlers/access_request.tsTrigger: license issuance calls sendWelcomeEmail()

Data flow

Inbound path

  1. External sender delivers to hello@, support@, or [email protected]
  2. CF MX records (route{1,2,3}.mx.cloudflare.net, priority 43/48/51) accept delivery
  3. CF Email Routing evaluates rules — all addresses plus catch-all forward to [email protected]
  4. Proton receives and stores. Regent reads on phone or desktop.

Outbound path (license delivery)

sequenceDiagram
participant U as User
participant W as Licensing Worker
participant R as Resend API
participant S as AWS SES (eu-west-1)
participant I as User inbox
U->>W: POST /v1/access-requests {email}
W->>W: generate license key, store in D1
W->>R: POST /emails {from: licenses@, to: user, key}
R->>S: relay via SES
S->>I: deliver with DKIM signature
Note over I: SPF passes (envelope-from: send.casaconomy.com)
Note over I: DKIM passes (resend._domainkey.casaconomy.com)
Note over I: DMARC passes (p=none → monitor)

DNS authentication records

The domain split isolates inbound and outbound SPF without collision.

TypeNamePurpose
MX (3 records)casaconomy.comCF Email Routing acceptance
TXT (SPF)casaconomy.cominclude:_spf.mx.cloudflare.net ~all — inbound only
TXT (DKIM)cf2024-1._domainkey.casaconomy.comCF Email Routing DKIM for forwarded mail
MXsend.casaconomy.comSES bounce feedback path
TXT (SPF)send.casaconomy.cominclude:amazonses.com ~all — outbound envelope-from
TXT (DKIM)resend._domainkey.casaconomy.comResend DKIM for From-header domain
TXT (DMARC)_dmarc.casaconomy.comv=DMARC1; p=none; rua=mailto:[email protected]; aspf=s; adkim=s

Why the subdomain split works: SPF checks the envelope-from (send.casaconomy.com), while DKIM and DMARC check the From-header domain (casaconomy.com). Each authentication mechanism validates against the right scope without interference.

DMARC ratchet plan: p=none (monitor) → p=quarantine after 1 clean week of aggregate reports → p=reject after 2 more clean weeks. Aggregate reports arrive at [email protected].

Secrets and tokens

All secrets are machine-local, never committed.

SecretScopeStorage
CLOUDFLARE_API_TOKENZone:DNS:Edit, Zone:Email Routing Rules:Edit~/.paperclip/secrets/cloudflare.env
RESEND_API_TOKENSend-only (production code + Worker)~/.paperclip/secrets/resend.env + wrangler secret
RESEND_ADMIN_TOKENFull access (operator tasks, revoked between sessions)~/.paperclip/secrets/resend.env

Failure modes + recovery

FailureWhat happensRecovery
CF Email Routing destination unverifiedInbound mail silently droppedRe-verify via cf email destinations; check regent’s Proton spam
Resend API token expired/revokedOutbound sends fail with 401; Worker returns 500 to callerRotate token in Resend dashboard, update wrangler secret put RESEND_API_TOKEN
DKIM key rotationOld key still valid during overlap; no gapResend handles rotation; verify via resend domains records
DMARC reject on legitimate mailMail quarantined or rejected by recipientCheck rua aggregate reports; if false positive, relax DMARC back to p=quarantine
SES bounce rate too highResend / SES may throttle or suspend sendingMonitor Resend dashboard; clean recipient list

What’s planned to change

  • DMARC ratchet — move from p=none to p=reject once aggregate reports show clean alignment (tracked manually, no CAS yet).
  • CAS-1093 (sync) — sync notifications may add a second outbound email trigger from sync.casaconomy.com Worker.
  • CAS-1100 (licensing tiers) — paid tier emails (receipts, renewal reminders) will add templates to workers/licensing/src/lib/email.ts.

Last reviewed: 2026-04-29 by Saga. Next review: 2026-07-29.

What changed {#what-changed}

This chapter was introduced in CAS-3637 Phase 3 (The Casaconomy Book) as the canonical reference for the email infrastructure.

See: CHANGELOG → 2026-05-18