Skip to content

Email Classification

The classifier runs inline in the email worker on every incoming message. It uses pattern matching — no LLM calls, no external API dependencies.

LabelDescription
spamFailed authentication (SPF + DKIM both failed)
cold_outreachMatches cold email patterns
newsletterHas List-Unsubscribe header
legitimateNo suspicious patterns detected
unknownFreemail sender with vague subject

Cloudflare adds an X-Cf-Spamh-Score header (0–100, higher = more spammy) to emails processed through Email Routing. If the score is 40 or above, the email is classified as spam. The threshold is configurable via the CF_SPAM_THRESHOLD constant in classifier.ts.

If both SPF and DKIM fail, the email is classified as spam.

3. Subject pattern matching → cold_outreach

Section titled “3. Subject pattern matching → cold_outreach”

The subject is tested against patterns commonly found in cold outreach:

  • “quick question”
  • “following up”
  • “partnership”
  • “15 min call”
  • “scale your” / “grow your”
  • “looking to connect”
  • Single first name followed by ? (e.g., “Eelco?”)
  • “let’s chat” / “let’s connect”
  • “reaching out”
  • “collaboration opportunity”
  • “synergy” variants

Presence of the List-Unsubscribe header indicates a mailing list or newsletter.

Section titled “5. Body calendar link patterns → cold_outreach”

If the body contains calendar scheduling links:

  • calendly.com
  • cal.com
  • hubspot.com/meetings
  • “book a time” / “schedule a call”

If the sender uses a freemail domain (Gmail, Outlook, Yahoo, etc.) and the subject is generic (e.g., “hi”, “hello”, “question”), it’s marked unknown for manual review.

Everything else is considered legitimate.

Edit the patterns in worker/src/services/classifier.ts. The classifier exports a single classify() function that returns { classification, reason }.

The architecture supports adding an optional Workers AI call for borderline cases. The plan is to use a small model (e.g., Llama 3 8B) with a simple prompt: “Classify this email as cold_outreach, spam, newsletter, or legitimate. Respond with one word.”

This would be opt-in per the settings, only triggered for emails classified as unknown.