AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

cloudflare-deploy

Deploy applications and infrastructure to Cloudflare using Workers, Pages, and related platform services. Use when the user asks to deploy, host, publish, or set up a project on Cloudflare.

Original source
openai
License
Apache-2.0
Pinned revision
49f948faa9258a0c61caceaf225e179651397431

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

This skill also requires local files or dependencies. Remote reading alone may not be enough.

Ask your assistant

Use Agentic Memory skills to read openai--cloudflare-deploy at revision 49f948faa9258a0c61caceaf225e179651397431, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 309

references/email-routing/gotchas.md

Gotchas & Troubleshooting

Critical Pitfalls

Stream Consumption (MOST COMMON)

Problem: "stream already consumed" or worker hangs

Cause: message.raw is ReadableStream - consume once only

Solution:

// ❌ WRONG
const email1 = await parser.parse(await message.raw.arrayBuffer());
const email2 = await parser.parse(await message.raw.arrayBuffer()); // FAILS

// ✅ CORRECT
const raw = await message.raw.arrayBuffer();
const email = await parser.parse(raw);

Consume message.raw immediately before any async operations.

Destination Verification

Problem: Emails not forwarding

Cause: Destination unverified

Solution: Add destination, check inbox for verification email, click link. Verify status: GET /zones/{id}/email/routing/addresses

Mail Authentication

Problem: Legitimate emails rejected

Cause: Missing SPF/DKIM/DMARC on sender domain

Solution: Configure sender DNS:

example.com. IN TXT "v=spf1 include:_spf.example.com ~all"
selector._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=..."
_dmarc.example.com. IN TXT "v=DMARC1; p=quarantine"

Envelope vs Header

Problem: Filtering on wrong address

Solution:

// Routing/auth: envelope
if (message.from === "[email protected]") { }

// Display: headers
const display = message.headers.get("from");

SendEmail Limits

| Issue | Limit | Solution | |-------|-------|----------| | From domain | Must own | Use Email Routing domain | | Volume | ~100/min Free | Upgrade or throttle | | Attachments | Not supported | Link to R2 | | Type | Transactional | No bulk |

Common Errors

CPU Time Exceeded

Cause: Heavy parsing, large emails

Solution:

const size = parseInt(message.headers.get("content-length") || "0") / 1024 / 1024;
if (size > 20) {
  message.setReject("Too large");
  return;
}

ctx.waitUntil(expensiveWork());
await message.forward("[email protected]");

Rule Not Triggering

Causes: Priority conflict, matcher error, catch-all override

Solution: Check priority (lower=first), verify exact match, confirm destination verified

Undefined Property

Cause: Missing header

Solution:

// ❌ WRONG
const subj = message.headers.get("subject").toLowerCase();

// ✅ CORRECT
const subj = message.headers.get("subject")?.toLowerCase() || "";

Limits

| Resource | Free | Paid | |----------|------|------| | Email size | 25 MB | 25 MB | | Rules | 200 | 200 | | Destinations | 200 | 200 | | CPU time | 10ms | 50ms | | SendEmail | ~100/min | Higher |

Debugging

Local

npx wrangler dev

curl -X POST 'http://localhost:8787/__email' \
  --header 'content-type: message/rfc822' \
  --data 'From: [email protected]
To: [email protected]
Subject: Test

Body'

Production

npx wrangler tail

Pattern

export default {
  async email(message, env, ctx) {
    try {
      console.log("From:", message.from);
      await process(message, env);
    } catch (err) {
      console.error(err);
      message.setReject(err.message);
    }
  }
} satisfies ExportedHandler;

Auth Troubleshooting

Check Status

const auth = message.headers.get("authentication-results") || "";
console.log({
  spf: auth.includes("spf=pass"),
  dkim: auth.includes("dkim=pass"),
  dmarc: auth.includes("dmarc=pass")
});

if (!auth.includes("pass")) {
  message.setReject("Failed auth");
  return;
}

SPF Issues

Causes: Forwarding breaks SPF, too many lookups (>10), missing includes

Solution:

; ✅ Good
example.com. IN TXT "v=spf1 include:_spf.google.com ~all"

; ❌ Bad - too many
example.com. IN TXT "v=spf1 include:a.com include:b.com ... ~all"

DMARC Alignment

Cause: From domain must match SPF/DKIM domain

Best Practices

  1. Consume message.raw immediately
  2. Verify destinations
  3. Handle missing headers (?.)
  4. Use envelope for routing
  5. Check spam scores
  6. Test locally first
  7. Use ctx.waitUntil for background work
  8. Size-check early