Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/email-workers/configuration.md
1# Email Workers Configuration23## wrangler.jsonc45```jsonc6{7"name": "email-worker",8"main": "src/index.ts",9"compatibility_date": "2025-01-27",10"send_email": [11{ "name": "EMAIL" }, // Unrestricted12{ "name": "EMAIL_LOGS", "destination_address": "[email protected]" }, // Single dest13{ "name": "EMAIL_TEAM", "allowed_destination_addresses": ["[email protected]", "[email protected]"] },14{ "name": "EMAIL_NOREPLY", "allowed_sender_addresses": ["[email protected]"] }15],16"kv_namespaces": [{ "binding": "ARCHIVE", "id": "xxx" }],17"r2_buckets": [{ "binding": "ATTACHMENTS", "bucket_name": "email-attachments" }],18"vars": { "WEBHOOK_URL": "https://hooks.example.com" }19}20```2122## TypeScript Types2324```typescript25interface Env {26EMAIL: SendEmail;27ARCHIVE: KVNamespace;28ATTACHMENTS: R2Bucket;29WEBHOOK_URL: string;30}3132export default {33async email(message: ForwardableEmailMessage, env: Env, ctx: ExecutionContext) {}34};35```3637## Dependencies3839```bash40npm install postal-mime mimetext41npm install -D @cloudflare/workers-types wrangler typescript42```4344Use postal-mime v2.x, mimetext v3.x.4546## tsconfig.json4748```json49{50"compilerOptions": {51"target": "ES2022", "module": "ES2022", "lib": ["ES2022"],52"types": ["@cloudflare/workers-types"],53"moduleResolution": "bundler", "strict": true54}55}56```5758## Local Development5960```bash61npx wrangler dev6263# Test receiving64curl --request POST 'http://localhost:8787/cdn-cgi/handler/email' \65--url-query '[email protected]' --url-query '[email protected]' \66--header 'Content-Type: text/plain' --data-raw 'Subject: Test\n\nHello'67```6869Sent emails write to local `.eml` files.7071## Deployment Checklist7273- [ ] Enable Email Routing in dashboard74- [ ] Verify destination addresses75- [ ] Configure DMARC/SPF/DKIM for sending76- [ ] Create KV/R2 resources if needed77- [ ] Update wrangler.jsonc with production IDs7879```bash80npx wrangler deploy81npx wrangler deployments list82```8384## Dashboard Setup85861. **Email Routing:** Domain → Email → Enable Email Routing872. **Verify addresses:** Email → Destination addresses → Add & verify883. **Bind Worker:** Email → Email Workers → Create route → Select pattern & Worker894. **DMARC:** Add TXT `_dmarc.domain.com`: `v=DMARC1; p=quarantine;`9091## Secrets9293```bash94npx wrangler secret put API_KEY95# Access: env.API_KEY96```9798## Monitoring99100```bash101npx wrangler tail102npx wrangler tail --status error103npx wrangler tail --format json104```105106## Troubleshooting107108| Error | Fix |109|-------|-----|110| "Binding not found" | Check `send_email` name matches code |111| "Invalid destination" | Verify in Email Routing dashboard |112| Type errors | Install `@cloudflare/workers-types` |113