> ## Documentation Index
> Fetch the complete documentation index at: https://learn.workflow.dog/llms.txt
> Use this file to discover all available pages before exploring further.

# Route Incoming Email

> Classify an incoming message and send it down the right workflow branch.

Email routing combines a service trigger with deterministic filters, optional
AI classification, and one branch per destination.

A typical workflow normalizes each new message, classifies it or applies fixed
rules, chooses a branch, then labels, drafts, forwards, replies, or notifies as
appropriate.

## Start with the narrowest trigger

Use a Gmail or Outlook new-email trigger and configure its built-in filters
when possible. Trigger filters avoid creating runs for messages the automation
will never process.

Remember that subject matching can be case-sensitive. Test with the exact
capitalization and message shapes that arrive in the real mailbox.

## Choose deterministic or AI routing

Use deterministic text and logic actions when the rule can be stated exactly:

* sender domain equals a known customer or vendor,
* subject starts with a fixed prefix,
* a label is present,
* body contains a specific identifier.

Use [OpenAI Chat](/reference/actions/openai/chat) with structured output when
the distinction depends on meaning rather than a fixed phrase. Keep the schema
small:

```json theme={null}
{
  "type": "object",
  "properties": {
    "route": {
      "type": "string",
      "enum": ["sales", "support", "billing", "ignore"]
    },
    "summary": { "type": "string" },
    "urgent": { "type": "boolean" }
  },
  "required": ["route", "summary", "urgent"],
  "additionalProperties": false
}
```

<Tip>
  Put hard safety rules before AI classification. For example, ignore your own
  automated senders and known newsletters before paying to classify the
  remaining messages.
</Tip>

## Build the branches

Connect `route` to a case-selection action or compare it in separate branches:

* `sales` can forward to the sales queue.
* `support` can add a label and draft a reply.
* `billing` can notify the billing team with the summary.
* `ignore` can end without a side effect.

Use [Conditional](/building/meta-controls) on side-effect actions so only the
matching branch runs. Independent preparation branches can still run
concurrently.

## Avoid mail loops

<Warning>
  A workflow that sends, forwards, or labels mail can trigger another
  email-based workflow—including itself. Filter automated senders, dedicated
  labels, or recognizable headers so generated messages do not loop.
</Warning>

Before enabling:

1. Send representative messages for every route.
2. Confirm the trigger data contains the body and attachments you expect.
3. Inspect drafts before switching to automatic replies.
4. Test the fallback branch for ambiguous messages.
5. Review Run History for node errors even when a run status says completed.

See [Service event triggers](/guides/service-triggers) for account and event
lifecycle behavior.
