Repository navigation
Email on Cloudflare, phase 1: staging mail - #1903
Merged
Merged
Conversation
* feat(email): Cloudflare provider behind a flag Add EMAIL_PROVIDER=cloudflare and a send_email binding path in sendEmail behind the unchanged dev fence. Resend stays the default. Cloudflare error codes map to EmailRejectedError or a plain Error. Tested with a binding recorder and Miniflare's send_email binding. * feat(email): Cloudflare path for broadcasts With EMAIL_PROVIDER=cloudflare, sendBroadcast sends one message per allowed recipient through sendEmail; the per-recipient fence and result accounting are unchanged and the Resend batch path stays for production. Tests use the shared binding recorder. * feat(email): store inbound mail in R2 Add the Worker email() handler. A message routed to the Worker is stored raw at inbound/raw/YYYY/MM/DD/<uuid>.eml with envelope metadata; with no MAIL_INBOUND binding it is rejected. Adds the EMAIL, EMAIL_PROVIDER and MAIL_INBOUND binding types and the ForwardableEmailMessage lint global. Tested against Miniflare R2 and the bundled Worker. * chore(staging): wire Cloudflare mail for dev Add the dev send_email binding restricted to the staging senders, the nemar-mail-dev inbound bucket, and EMAIL_PROVIDER, FROM_EMAIL and REPLY_TO for test.nemar.org. Only [env.dev] changes; production stays on Resend. * docs: ADR 0110 and email epic notes Record the move to the Cloudflare Email Service as a proposed ADR, add the epic working notes, and link them from the context index. * fix(email): refuse an unknown EMAIL_PROVIDER An unknown provider value now throws EmailProviderConfigError instead of using Resend, and that error counts as a certain non-delivery. The resolver returns the provider with its binding, used by sendEmail and broadcast. * fix(email): bound each broadcast send On the Cloudflare provider each per-recipient send in sendBroadcast is bounded, so a hung binding fails that recipient instead of holding the admin request. * fix(email): byte-clamp inbound metadata, retry put Clamp the three header-derived metadata values by UTF-8 bytes without splitting a character, and retry a failed put once without metadata so the message is kept. The body stays buffered because the retry needs the bytes again. * feat(email): add a text part on the Cloudflare path Derive a plain-text alternative from the HTML with a small dependency-free converter; codes and links survive. The Resend request is unchanged. * docs: align ADR 0110 and epic notes Match the strict EMAIL_PROVIDER rule and the text part, place the index entry after ADR 0109, and correct the Wrangler pin note. * fix(email): harden the HTML to text converter Decode each link label, url and text exactly once and never re-strip decoded text, look entities up in a Map, read unquoted href, cap the input at 256 KiB, and scan blocks and links forward once so unclosed tags cost linear time.
The apex MX moved to Email Routing on 2026-10-23 with the catch-all forwarding as before, and the soak fallback is limited to refusals that certainly sent nothing. Epic phase table matches the issues.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1903Version: 🤖 Updated on each push. |
This was referenced Oct 24, 2026
4 tasks done
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 of the email epic reaches
dev, so the staging Worker deploys with it. The epic continues on its branch afterwards; this PR does not close #1893.nemar-api-dev) sends through the Cloudflare Email Servicesend_emailbinding fromtest.nemar.orginstead of Resend (EMAIL_PROVIDER=cloudflare), with a plain-text part, behind the unchanged non-production delivery fence. Production sets nothing and stays on Resend.email()handler stores inbound mail for routedtest.nemar.orgaddresses in the privatenemar-mail-devbucket; a Worker without that bucket rejects mail.Phase PR: #1902 (two review rounds, all findings fixed). Part of #1893; #1894 closes after the staging checks below.
Prerequisites (done)
test.nemar.orgtest.nemar.orgas a routing subdomainnemar-mail-devbucket created, private, 30-day expiryTest plan
send_emailbindingtest.nemar.orgtonemar-api-dev(operator, after deploy)[email protected]with SPF and DKIM passingsupport@and[email protected]lands innemar-mail-dev; an unrouted address bounces🤖 Generated with Claude Code