If your inbox is a dumping ground for support requests, sales inquiries, partnership pitches, and spam — all landing in the same queue — you’re already paying a tax on every hour you spend triaging manually. n8n Claude email automation solves this with a workflow that reads Gmail, classifies each message using Claude, tags it, and routes it to the right Slack channel or team member, automatically. No custom code required if you stay inside n8n’s visual editor. This guide walks you through the full production setup: credential wiring, Claude prompt design, routing logic, and escalation handling — with the exact node configuration that actually works.
What You’re Building (and What It Actually Costs)
The workflow has five stages: Gmail trigger → extract email content → classify with Claude → apply routing rules → deliver to destination (Slack, ticket system, or human escalation). Every stage runs inside n8n, either self-hosted or on n8n Cloud.
Running this on Claude Haiku 3.5 with a ~500-token classification prompt costs roughly $0.0004 per email at current pricing ($0.80/M input tokens, $4/M output). A 1,000-email/day inbox costs under $0.40/day in API fees. If you’re on a higher-traffic plan and want to cut that further, prompt caching on repeated system instructions can knock 30–50% off — see the LLM caching strategies guide for implementation specifics.
For classification accuracy, Haiku is genuinely sufficient for 4–6 category routing. Upgrade to Claude Sonnet 3.5 if you need nuanced intent detection (distinguishing an angry churn risk from a general complaint, for example). The cost difference is ~10x, so benchmark before committing.
Node-by-Node Setup in n8n
Step 1: Gmail Trigger
Add a Gmail Trigger node. Set it to poll every 1–5 minutes (or use Gmail’s push via Pub/Sub if you need near-real-time). Connect your Google OAuth2 credentials — n8n’s credential manager handles the token refresh automatically.
Set the trigger to fire on New Email and filter to your target label if you pre-filter in Gmail (e.g., only emails landing in a “Support” label). If you want to catch everything, leave the label field blank and handle filtering downstream in the workflow logic.
Two fields to extract explicitly in the Gmail node settings: subject and text (plain text body). Avoid passing raw HTML to Claude — it wastes tokens and confuses classification. Use the Code node or Set node to strip HTML if your emails are HTML-heavy.
Step 2: Sanitise and Truncate
Add a Set node immediately after the trigger. Create a field called email_content with this expression:
// Trim to first 1500 chars — more than enough for classification
// Gmail trigger provides {{$json.text}} for plain text body
{{ ($json.subject + "\n\n" + $json.text).slice(0, 1500) }}
This keeps your prompt lean. The subject line is often the most signal-dense part of the message, so always include it first.
Step 3: Classify with Claude
Add an HTTP Request node (n8n’s Anthropic node works too if you’re on a version that has it, but HTTP Request gives you more control). Configure it as POST to https://api.anthropic.com/v1/messages with these headers:
{
"x-api-key": "YOUR_ANTHROPIC_API_KEY",
"anthropic-version": "2023-06-01",
"content-type": "application/json"
}
Body (use n8n’s JSON body mode):
{
"model": "claude-haiku-4-5",
"max_tokens": 100,
"system": "You are an email classifier. Respond ONLY with a JSON object: {\"category\": \"<category>\", \"urgency\": \"<high|medium|low>\", \"summary\": \"<one sentence>\"}. Categories: support, sales, billing, partnership, spam, other.",
"messages": [
{
"role": "user",
"content": "Classify this email:\n\n{{ $json.email_content }}"
}
]
}
The system prompt is deliberately minimal. Constraining the output to a small JSON object means you get consistent, parseable responses instead of prose. Set max_tokens to 100 — the classification response is always under 80 tokens, so you’re not paying for what you don’t need. For more on getting reliable structured JSON from Claude, the structured output guide covers edge cases and fallback handling in depth.
Step 4: Parse the Classification
Add a Code node after the HTTP Request. Extract the JSON from Claude’s response:
// Claude returns the content in items[0].content[0].text
const rawText = $input.item.json.content[0].text;
// Strip any markdown code fences if present
const cleaned = rawText.replace(/```json\n?/g, '').replace(/```/g, '').trim();
const parsed = JSON.parse(cleaned);
return {
category: parsed.category,
urgency: parsed.urgency,
summary: parsed.summary,
// pass through original email fields
subject: $('Gmail Trigger').item.json.subject,
from: $('Gmail Trigger').item.json.from,
threadId: $('Gmail Trigger').item.json.threadId
};
Claude occasionally wraps JSON in backtick code fences even when instructed not to. The replace() calls above handle that. Alternatively, append “Do not use markdown formatting” to your system prompt — I’ve found both approaches necessary in production because model behavior varies slightly across API versions.
Routing Logic: IF Nodes and Switch
n8n’s Switch node is the right tool here. Connect it after your Code node and set the Value 1 field to {{ $json.category }}. Add output branches for each category:
- support → Slack #support-queue + create Zendesk/Linear ticket
- sales → Slack #sales-inbound + add to CRM (HubSpot node)
- billing → Slack #finance-alerts + tag in Gmail
- partnership → Email forward to partnerships@yourcompany.com
- spam → Gmail: apply “Spam-Auto” label, archive
- other → Slack #general-inbox for human review
Urgency Escalation Layer
Add an IF node on the support branch that checks {{ $json.urgency === 'high' }}. When true, branch to a second Slack message that @channel-pings or DMs your on-call person. When false, post quietly to the queue channel.
Your Slack message node body should look like this for high-urgency items:
{
"channel": "#support-urgent",
"text": "🚨 *Urgent email from {{ $json.from }}*\n*Subject:* {{ $json.subject }}\n*Summary:* {{ $json.summary }}\n\n@channel please triage immediately."
}
For normal-priority items, drop the @channel and use a cleaner format without the emoji alarm. The signal-to-noise ratio in Slack matters — if every message pings @channel, people stop reading them.
Gmail Labelling (Close the Loop)
After routing, add a Gmail node set to Modify Labels. Apply a label like AI-Classified/Support or AI-Classified/Sales to the original thread. This gives you a paper trail, lets you audit misclassifications, and prevents re-processing the same email on the next poll cycle.
To prevent re-processing: in your Gmail Trigger, set the filter to only fetch emails that do not have any AI-Classified label. This is the cleanest deduplication approach without needing an external database.
Where This Breaks in Production
A few failure modes I’ve hit that the n8n documentation doesn’t warn you about:
Long email threads: Gmail’s trigger returns the full thread text for replies, which can be 5,000+ tokens. Your 1,500-character truncation handles this, but sometimes the most relevant text is at the bottom of a thread (the new reply). Slice from the end instead: text.slice(-1500) for reply detection workflows.
Non-English emails: Claude handles multilingual classification well, but your category labels are in English. Add “Respond in English regardless of input language” to your system prompt, or you’ll occasionally get {"category": "soporte"} back.
Rate limits: At 5-minute poll intervals with Gmail’s 100-result-per-poll cap, you’re fine up to ~28,000 emails/day. Above that, switch to Pub/Sub push or use n8n’s queue mode with concurrency limits. If you’re hitting Anthropic rate limits, add a Wait node with a 1-second delay between Claude calls — this is enough to stay under Haiku’s default tier limits.
n8n timeouts: The HTTP Request node has a default 10-second timeout. Claude Haiku responses come back in under 2 seconds typically, but add buffer: set timeout to 30 seconds. On n8n Cloud’s free tier, workflow executions also have memory limits — if you’re processing attachments, self-host.
If you’re building more complex multi-step agents on top of this, the fallback logic guide covers how to handle model timeouts and API errors gracefully without losing emails in the queue.
Testing Before You Go Live
Build a test Gmail account and send 20–30 representative emails across each category you care about. Run the workflow manually in n8n (use the “Execute Workflow” button, not the trigger, so you control timing). Check the Code node output to confirm JSON is parsing cleanly.
For classification accuracy, I typically see 92–95% accuracy on well-defined categories with Haiku. The failures cluster around ambiguous emails: a “billing” question asked by a sales prospect, or a partnership pitch disguised as a support request. You can handle these with a confidence score — add a "confidence": 0.0–1.0 field to your prompt and route low-confidence items to a human review channel regardless of category.
If you want to extend this into outbound — auto-drafting replies for common support questions — the architecture is covered in the Claude email agent guide, which picks up where this routing workflow ends.
Bottom Line: Who Should Build This
Solo founders handling 50–200 emails/day: build this in an afternoon, run it on n8n Cloud’s Starter plan ($20/month). The API costs are negligible. ROI is immediate if you’re manually triaging more than 30 minutes/day.
Small teams (2–10 people) with a shared inbox: self-host n8n on a $6 DigitalOcean droplet to avoid per-execution limits, connect to your team’s Slack and CRM. Add ticket creation to the support branch from day one — the extra 10 minutes of setup saves weeks of “did anyone handle this?” conversations.
Larger operations with SLA requirements: use Sonnet 3.5 instead of Haiku for the classification step, add a logging branch that writes every classification to a Google Sheet or Postgres table, and implement the confidence-score fallback. You’ll want audit trails when someone asks why a high-priority customer email went to the wrong queue. For platform decisions at scale, the n8n vs Zapier vs Activepieces comparison is worth reading before committing to n8n long-term.
The n8n Claude email automation stack described here is production-ready as written. It handles the 95% case reliably, costs almost nothing to run, and takes under two hours to configure from scratch. The remaining 5% — edge cases, retraining your category definitions, handling email threads — you’ll tune over the first week of live operation as you see where the misclassifications cluster.
Frequently Asked Questions
Which Claude model should I use for email classification in n8n?
Claude Haiku 3.5 is the right default — it’s fast (under 2 seconds), accurate enough for 4–8 category classification, and costs roughly $0.0004 per email. Upgrade to Sonnet 3.5 only if you need nuanced intent detection (e.g., differentiating churn risk from general complaints). The ~10x cost difference rarely justifies it for standard routing.
How do I prevent n8n from processing the same email twice?
Apply a Gmail label (like “AI-Classified”) after processing each email, then filter your Gmail Trigger to only fetch emails without that label. This is cleaner than using n8n’s built-in deduplication because it survives workflow restarts and is visible directly in Gmail for debugging.
Can I use n8n’s built-in Anthropic node instead of HTTP Request?
Yes, if your n8n version includes it. The Anthropic node simplifies credential management but gives you less control over request parameters like timeout settings and headers. For production workflows where you need prompt caching headers or custom retry logic, stick with the HTTP Request node and manage credentials via n8n’s credential store.
How do I handle emails that Claude misclassifies?
Add a confidence score field to your classification prompt and route anything below 0.75 to a human review Slack channel regardless of the assigned category. Track misclassifications in a Google Sheet for two weeks, then refine your category definitions and few-shot examples in the system prompt. Most accuracy issues come from poorly defined category boundaries, not model limitations.
What’s the difference between running this on n8n Cloud vs self-hosted?
n8n Cloud’s Starter plan ($20/month) limits you to 2,500 workflow executions/month — fine for low-volume inboxes but expensive per-execution at scale. Self-hosting on a $6 VPS removes execution limits entirely. Go self-hosted if you’re processing more than ~80 emails/day or want to run multiple workflows without worrying about quota.
Can this workflow auto-reply to emails instead of just routing them?
Yes — add a Gmail “Send Email” node after your routing logic with a Claude-generated draft as the body. Limit auto-replies to clearly defined categories (like common FAQ support questions) and always CC a human on the first send. Full implementation details including draft generation and reply-threading are covered in the Claude email agent article linked in this guide.
Put this into practice
Browse our directory of Claude Code agents — ready-to-use agents for development, automation, and data workflows.
Editorial note: API pricing, model capabilities, and tool features change frequently — always verify current details on the vendor’s website before building in production. Code examples are tested at time of writing; pin your dependency versions to avoid breaking changes. Some links in this article may be affiliate links — we may earn a commission if you sign up, at no extra cost to you.

