Automatic Email Categorization and Organization with Outlook and GPT-4o

Go to Workflow
0 views
Built by Can KURT Can KURT
Created on June 08, 2026

Description

n8n – Outlook AI Categorization & Labeling (Fully Automated)

> Zero manual mapping. The workflow automatically discovers your Outlook folders, understands the context, assigns the correct category, and moves the email into the right folder. It uses the original Microsoft Outlook nodes plus an AI Agent. You can connect OpenAI or any other LLM provider.

✨ Features

Self-Discovery:** Scans your Outlook folders automatically – no manual mapping required.
AI-Powered Decisions:** Considers sender, subject, content, links, attachments, timing, and business context.
Label + Move:** Assigns the right Outlook category and moves the email into the correct folder.
Dual Category Logic:** Can apply both a primary and a secondary category (e.g., Action + Project).
Error Handling:** Captures errors and continues without breaking the workflow.
Flexible AI Backend:** Replace OpenAI with your own LLM if preferred.

🚀 Setup (5 Steps)

Connect Outlook
In n8n → Credentials → Microsoft Outlook, grant at least Mail.ReadWrite.

Connect AI
In n8n → Credentials, set up OpenAI (or another model). Works best with GPT-4.x or GPT-4o.

Import the Workflow
n8n → Workflows → Import from File/Clipboard and paste the provided JSON.

Enable Trigger
Adjust the Schedule Trigger (e.g., every 5 minutes).

Run & Verify
Test run and watch emails get categorized and moved automatically.

🧠 How It Works

Schedule Trigger pulls new emails
Loop Over Items processes them one by one
Markdown / varEmail cleans the content
Get Many Folders fetches Outlook categories and folders
Summarize + Code prepare category IDs
AI Agent applies deep categorization logic
Update Category applies the Outlook category
Move Folder places the email in the right folder
Error Handling ensures workflow stability

🧩 System Prompt Example

You are an advanced AI email categorization system. Your mission is to intelligently analyze and categorize emails with maximum accuracy and context awareness.

INTELLIGENT CATEGORIZATION ENGINE:

Parse all available categories: {{ $json.category }}
Multi-layer analysis: Sender, Subject, Body, Links, Attachments
Prioritize: Security threats, Action Required, Business Context
Specialized: SaaS, Hosting, E-commerce, Finance, Support, Corporate
Anti-Spam: Pattern detection, spoofing, red-flag subjects
Dual Logic: Primary + Secondary categories when applicable

OUTPUT FORMAT (JSON only):
{
"subject": "EXACT_EMAIL_SUBJECT",
"category": "PRIMARY_CATEGORY_FROM_AVAILABLE_LIST",
"subCategory": "SECONDARY_CATEGORY_IF_APPLICABLE",
"analysis": "Reasoning",
"confidence": "HIGH/MEDIUM/LOW"
}

Available Categories: {{ $json.category }}

⚙️ Parameters & Notes

Uses only existing Outlook categories (never invents new ones).
Works with any LLM that supports Chat Completions.
Requires Mail.ReadWrite permissions.
Safe fallback: if unsure, it uses the Action category.

🛡️ Security

Processes only what is needed for classification.
No external logging of email content unless you configure it.
AI provider can be swapped for self-hosted LLMs for compliance.

📄 License & Sharing

License:** MIT (or your choice).
Tags:** n8n, Outlook, Email, AI, Automation, Categorization
Import Method:** Copy/paste workflow JSON into n8n.

✅ Summary

Connect → Import → Run.
No manual mapping. AI-powered categorization that labels and organizes your Outlook mailbox automatically.

Nodes Used (4)

AI Agent
@n8n/n8n-nodes-langchain.agent
Code
n8n-nodes-base.code
Microsoft Outlook
n8n-nodes-base.microsoftOutlook
OpenRouter Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenRouter