feat(driver): add Cloudflare Email Service (Email Sending) - #101
Open
jd-solanki wants to merge 1 commit into
Open
feat(driver): add Cloudflare Email Service (Email Sending)#101jd-solanki wants to merge 1 commit into
jd-solanki wants to merge 1 commit into
Conversation
Add unemail/driver/cloudflare-email-service for Cloudflare's Email Service API. The existing cloudflare-email driver targets Email Routing: it builds raw RFC 5322 and needs the Workers-only EmailMessage class from the virtual cloudflare:email module. Email Service takes structured fields on the same send_email binding, so the new driver needs no ambient global, no virtual module and no MIME builder, and sends to multiple recipients in one call. Binding E_* errors are mapped onto the EmailErrorCode taxonomy so retry middleware sees rate limits as retryable and validation failures as not. Includes tests, package + jsr exports, and a drivers.md matrix row. Closes productdevbook#100 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
jd-solanki
marked this pull request as ready for review
July 22, 2026 10:05
Author
|
This is created by AI so I highly recommend you check out any issues or refactoring you may prefer. If possible, can you make a new release after merging? |
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.
Closes #100. Opened as a draft because one design question is still open — see Shape below.
What
Adds
unemail/driver/cloudflare-email-servicefor Cloudflare's Email Service (Email Sending), alongside the existingcloudflare-emaildriver.The two speak different APIs on the same
send_emailbinding:cloudflare-email(existing)cloudflare-email-service(new)buildMimecloudflare:emailEmailMessage)normalizeAddresses(msg.to)[0])Practical effects: no ambient global and no virtual-module import (so no
"cloudflare:email" could not be resolvedwarning in Vite dev), no_smtp/mimein the built module, and display names come through as structuredfrom: { email, name }rather than depending on a MIME header.Binding errors arrive as
Errors carrying anE_*code. Those are mapped onto the existingEmailErrorCodetaxonomy, soretrymiddleware treatsE_RATE_LIMIT_EXCEEDEDas retryable andE_VALIDATION_ERROR/E_SENDER_NOT_VERIFIEDas not. Unrecognised codes fall through totoEmailError→PROVIDER, as before.Shape
The issue offered either a separate driver or a mode flag on the existing one, and left the choice to you. This PR takes the separate-driver route because it's non-breaking —
cloudflare-emailis untouched for Email Routing users. Happy to reshape it into a mode flag on the existing driver instead if you'd prefer; that's the reason this is a draft.Correction to the issue
The issue proposed omitting the
attachmentsflag. That was wrong — I re-checked the current Workers binding docs and Email Service does accept structured attachments, so the driver supports them and mapscontentType→type,cid→contentId. The issue's sketch also listedcc/bccinflags, which aren't keys ofDriverFlags; the actual flags arehtml,text,attachments,customHeaders,replyTo.Included
test/driver/cloudflare-email-service.test.ts)docs/drivers.mdmatrix row + a section on the Routing-vs-Service distinctionpackage.jsonandjsr.jsonexport entriesVerification
pnpm lint,pnpm typecheck,vitest run(281 tests, 56 files),pnpm buildandpnpm bundle-budgetall pass locally.One caveat, stated plainly: this surface was validated against Cloudflare's current documentation and the unemail source, and is covered by unit tests against a mock binding — but I have not exercised the send path against a live Cloudflare binding. Worth a second pair of eyes on the payload field names before release.