How to Build an AI Email Triage System with n8n (Step-by-Step Guide)
If you've ever stared at an inbox with 200+ unread emails wondering where to even start, you already know the problem. Email is still the backbone of business communication, but it's also one of the biggest productivity killers. The average knowledge worker spends 28% of their workday managing email.
What if an AI could read every incoming email, classify its urgency, route it to the right person, and draft a response — all before you even open your inbox?
In this guide, we'll build exactly that: an AI-powered email triage system using n8n workflow automation. No proprietary SaaS lock-in. Fully self-hostable. Production-ready.
What We're Building
Our AI email triage workflow will:
- Monitor an inbox for new emails (Gmail/IMAP)
- Classify each email by urgency and category using an LLM
- Route emails to the right team member or channel
- Draft smart replies for routine messages
- Escalate urgent items via Slack/Teams notification
The entire system runs on n8n, the open-source workflow automation platform, and costs virtually nothing to operate at scale.
Prerequisites
- n8n instance (self-hosted or n8n Cloud) — install guide
- Email account with IMAP access or Gmail API credentials
- OpenAI API key (or any LLM provider — Anthropic, Ollama, etc.)
- Slack workspace (optional, for notifications)
- Basic familiarity with JSON and REST APIs
Architecture Overview
[Email Trigger] → [Fetch Content] → [AI Classification] → [Router]
├── Urgent → Slack Alert + Label
├── Sales Lead → CRM + Auto-Reply Draft
├── Support → Ticket System + Draft
└── Newsletter/Spam → Archive
This is a classic n8n email automation pattern: trigger, enrich, classify, branch, act. Let's build each stage.
Step 1: Set Up the Email Trigger
Create a new workflow in n8n and add an Email Trigger (IMAP) node — or use the Gmail Trigger node if you're on Google Workspace.
Node: Gmail Trigger
- Authentication: OAuth2 (connect your Google account)
- Poll Times: Every 2 minutes
- Label: INBOX
- Simple: false (we want full headers + body)
For IMAP users:
Node: IMAP Email Trigger
- Host: imap.yourdomain.com
- Port: 993
- SSL: true
- Mailbox: INBOX
Tip: In production, set poll frequency based on your SLA requirements. For sales teams, every 1-2 minutes. For internal ops, every 5-10 minutes is fine.
The trigger outputs an object per email containing from, to, subject, text (plain body), and html.
Step 2: Extract and Normalize Email Content
Add a Code node (JavaScript) to clean the email body and prepare a structured payload for the AI.
Node: Code — "Prepare Email Payload"
const items = $input.all();
return items.map(item => {
const email = item.json;
// Strip HTML tags, keep plain text
const body = (email.text || email.html || '')
.replace(/<[^>]*>/g, '')
.replace(/\s+/g, ' ')
.trim()
.substring(0, 3000); // Token budget control
return {
json: {
messageId: email.messageId || email.id,
from: email.from?.text || email.from,
subject: email.subject || '(no subject)',
body: body,
date: email.date,
hasAttachments: (email.attachments?.length || 0) > 0
}
};
});
This step is critical for keeping LLM costs low. We cap the body at 3000 characters — enough context for classification without burning tokens on email signatures and thread history.
Step 3: AI Classification with an LLM
This is the core of our AI email triage system. Add an OpenAI node (or HTTP Request node for other providers).
Node: OpenAI — "Classify Email"
- Resource: Chat Completion
-
Model:
gpt-4o-mini(fast, cheap, accurate enough for classification) - System Prompt:
You are an email triage assistant. Classify the incoming email and respond ONLY with valid JSON.
Categories: URGENT, SALES_LEAD, SUPPORT, INTERNAL, NEWSLETTER, SPAM
Urgency: 1 (low) to 5 (critical)
JSON schema:
{
"category": "CATEGORY",
"urgency": 1-5,
"summary": "one-line summary",
"suggested_action": "reply|forward|archive|escalate",
"draft_reply": "short professional reply if applicable, or null"
}
- User Message:
From: {{ $json.from }}
Subject: {{ $json.subject }}
Body: {{ $json.body }}
- Temperature: 0.1 (we want deterministic classification)
- Response Format: JSON
Why gpt-4o-mini? For classification tasks, smaller models perform nearly as well as GPT-4 at a fraction of the cost. We're talking about $0.00015 per email. At 1000 emails/day, that's $0.15/day — or about $4.50/month.
Step 4: Parse the AI Response
Add another Code node to parse the JSON response and handle edge cases.
Node: Code — "Parse Classification"
const items = $input.all();
return items.map(item => {
let classification;
try {
const content = item.json.message?.content || item.json.text || '';
classification = JSON.parse(content);
} catch (e) {
// Fallback for malformed responses
classification = {
category: 'INTERNAL',
urgency: 3,
summary: 'Could not classify',
suggested_action: 'forward',
draft_reply: null
};
}
return {
json: {
...item.json,
classification
}
};
});
Always add fallback handling. LLMs occasionally return malformed JSON, and your workflow should never break because of it.
Step 5: Route with a Switch Node
Now for the routing logic. Add a Switch node to branch based on classification.
Node: Switch — "Route by Category"
Configure the following outputs:
| Output | Condition |
|---|---|
| Urgent | classification.urgency >= 4 |
| Sales Lead | classification.category == "SALES_LEAD" |
| Support | classification.category == "SUPPORT" |
| Archive | classification.category IN ["NEWSLETTER", "SPAM"] |
| Default | Fallback for everything else |
Order matters here. Urgency check comes first so that an urgent sales lead still triggers the escalation path.
Step 6: Build the Action Branches
Branch A: Urgent Emails — Slack Alert
Node: Slack — "Send Urgent Alert"
-
Channel:
#urgent-inbox - Message:
:rotating_light: *Urgent Email*
From: {{ $json.from }}
Subject: {{ $json.subject }}
Summary: {{ $json.classification.summary }}
Action: {{ $json.classification.suggested_action }}
Branch B: Sales Leads — CRM + Auto-Reply Draft
Node: HTTP Request — "Create CRM Lead"
Send a POST request to your CRM (HubSpot, Pipedrive, Airtable, etc.) with the lead data.
Node: Gmail — "Create Draft Reply"
- Operation: Create Draft
-
To:
{{ $json.from }} -
Subject:
Re: {{ $json.subject }} -
Body:
{{ $json.classification.draft_reply }}
This doesn't send — it creates a draft for human review. AI handles the heavy lifting; humans make the final call.
Branch C: Support — Ticket Creation
Node: HTTP Request — "Create Support Ticket"
POST to your ticketing system (Linear, Jira, Zendesk) with the parsed summary and urgency level.
Branch D: Newsletter/Spam — Auto-Archive
Node: Gmail — "Archive and Label"
- Operation: Add Label
- Label: "Auto-Triaged/Low Priority"
- Operation: Mark as Read
Step 7: Add Logging and Monitoring
Add a final Spreadsheet/Database node at the end of each branch to log every classification decision.
Node: Google Sheets — "Triage Log"
| Timestamp | From | Subject | Category | Urgency | Action Taken |
|---|
This gives you an audit trail and data to fine-tune your prompts over time.
Production Hardening Tips
Rate limiting: Add a 200ms delay between API calls if processing batch catches up. Use the n8n Wait node.
Error handling: Wrap your AI classification in an Error Trigger workflow that retries failed classifications.
Prompt versioning: Store your system prompt in an environment variable or database so you can update it without editing the workflow.
Cost monitoring: Track token usage per classification. Set up alerts if daily spend exceeds thresholds.
Human-in-the-loop: For the first 2 weeks, route ALL auto-actions to a review queue. Measure accuracy before enabling full automation.
Performance Benchmarks
In our production deployments, this workflow achieves:
- Classification accuracy: 92-96% (measured against human reviewers)
- Processing time: ~2.3 seconds per email (including LLM call)
- Cost: $0.00015 per email with gpt-4o-mini
- Monthly cost at 1000 emails/day: ~$4.50
For comparison, a human email triager costs $15-25/hour and processes roughly 60-80 emails per hour.
Extending the System
Once your base triage is running, you can layer on:
- Sentiment analysis for customer-facing emails
- Language detection + auto-translation for international teams
- Calendar extraction for meeting requests (parse dates, create events)
- Attachment classification (invoices, contracts, marketing materials)
- Weekly digest generation summarizing email patterns and response times
Each of these is a matter of adding 2-3 nodes to your existing workflow.
The Bigger Picture
This email triage system is just one piece of what's possible with workflow automation and AI. The same pattern — trigger, classify, route, act — applies to:
- Customer support ticket routing
- Lead scoring and qualification
- Document processing and data extraction
- Social media monitoring and response
- Invoice processing and approval workflows
The companies that automate these operational bottlenecks now will have a compounding advantage over the next 5 years.
Need This Built for Your Business?
At Altiora, we design and deploy production-grade AI automation systems for businesses that want to stop drowning in manual operations and start scaling.
We don't sell templates. We build custom n8n email automation workflows, AI classification pipelines, and end-to-end operational systems — tailored to your stack, your team, and your growth targets.
What we deliver:
- Full workflow design, build, and deployment
- LLM prompt engineering optimized for your domain
- Monitoring dashboards and alerting
- Ongoing optimization as your needs evolve
Ready to automate your operations? Reach out at X: @AltioraHQ or visit altiorahq.com to book a strategy call.
We're a lean AI automation agency that ships fast and builds systems that actually work in production. No slide decks. No fluff. Just working automation.
Top comments (0)