This example deploys a Cloudflare Worker with an alchemy.run Stack and sends
mail through a Cloudflare send_email binding using the
CloudflareEmailService transport.
- A Cloudflare account with Email Service/Email Routing enabled for your sender domain.
- A verified destination address for the binding.
- Alchemy configured for Cloudflare (
bunx alchemy configureorCLOUDFLARE_API_TOKEN).
-
Build the local package from the repository root:
bun install bun run build
-
Edit
src/email.tsand replace the example sender/destination:export const SENDER = "bot@yourdomain.com" export const DESTINATION = "you@example.com"
-
Install the example dependencies:
cd examples/alchemy bun install
bun run devUnder alchemy dev, the binding writes messages to Alchemy's local email
simulator instead of delivering them.
bun run deployThe Stack output prints the Worker URL. Test it with:
curl -X POST "$WORKER_URL/send" \
-H 'content-type: application/json' \
-d '{"subject":"Hello","text":"Sent through effect-email and alchemy.run."}'alchemy.run.tsdefines the Stack, Cloudflare providers, state, and Worker.src/email.tsdeclares a restrictedsend_emailbinding.src/worker.tsobtains the raw binding throughCloudflare.Email.Send, wraps it withCloudflareEmailService.make, and uses the normalEmail.layer/Email.sendAPI.
The Worker keeps the Effect service and layer graph in the construction phase and sends one email per request.