AI-Powered Outlook Email Categorization - n8n Workflow

Automate Microsoft Outlook email sorting using a custom local AI agent (Ollama). This advanced n8n workflow template processes, categorizes, and moves emails to specific folders.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Freelance professionals and businesses receiving high volumes of email.

  • Users prioritizing local AI (Ollama) integration into their automation stack.

  • Technical users seeking robust n8n templates for advanced email flow control.

  • Anyone needing specific, customizable email routing logic beyond standard client filters.

Overview

The challenge of manually managing an overwhelming Outlook inbox, especially differentiating between critical business communications, necessary SaaS updates, and promotional content, is solved by this sophisticated n8n workflow. It leverages the power of a local Large Language Model (LLM) via Ollama to analyze the content, sender, and subject of uncategorized emails. By defining strict categorization rules (such as 'action', 'junk', 'receipt', or 'business') in the n8n node configuration, this n8n template ensures every relevant email is correctly tagged and moved to the appropriate folder automatically. This saves significant time and ensures high-priority items are never missed, making this n8n workflow a powerful tool for inbox zero efficiency.

How it Works

The process begins with the n8n trigger, designed for manual testing or scheduling. The initial Microsoft Outlook n8n node fetches a batch of emails based on specific filters: only messages that are not flagged and do not currently have any category assigned are processed. These messages are then iterated through using a Loop Over Items n8n node.

First, the email content is sanitized. A Markdown n8n node converts the HTML body, and a subsequent Set n8n node cleans up artifacts (like markdown links and excessive whitespace) to provide the AI Agent with pristine input. The n8n workflow then passes the cleaned data, along with the predefined allowed categories, to the AI Agent n8n node. This agent, connected to the local Ollama Chat Model n8n node, analyzes the email and outputs the category, subcategory, and analysis reasoning in a strict JSON format.

The resulting JSON is parsed (with built-in error handling to continue even if the JSON is malformed), and a Switch n8n node directs the flow based on the AI's primary category (e.g., 'junk', 'receipt', 'SaaS'). For each output, a corresponding set of Microsoft Outlook n8n nodes first applies the AI-determined category tags and then moves the email to the correct Outlook folder. For high-priority categories ('action' and 'business'), an If n8n node checks if the email has already been read. If read, it is moved to a final 'Actioned' archive folder, providing clear separation for human-reviewed items.

Installation Guide


  1. Import the n8n workflow: Copy the provided JSON data and import it directly into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Set up Credentials: This n8n workflow requires two main connections:

Microsoft Outlook: Configure an OAuth2 or API key credential for the Microsoft Outlook n8n node (used throughout the flow) to enable reading, updating categories, and moving messages.
Ollama: Ensure your local Ollama server is running and accessible. Configure the Ollama Chat Model n8n node (Ollama Chat Model1) with your API URL. Verify that the specified model (qwen2.5:14b) is installed on your Ollama server.

  1. Customize Categories and Folders: Review the varID & Category1 Set n8n node to adjust the list of categories and subcategories the AI can use. Crucially, update the folder IDs in the 'Move to Folders' Microsoft Outlook n8n nodes (e.g., Microsoft Outlook10, 15, 17, 19) to match the actual folder IDs in your Outlook account structure.

  2. Activate and Test: After configuring all connections and settings, activate the n8n workflow. Run the manual n8n trigger to ensure the categorization and movement logic functions correctly.

Node Details

This n8n workflow relies on several specialized nodes:

Microsoft Outlook23 (Trigger/Fetch n8n node):
Function: Serves as the primary data source, pulling emails.
Key Configuration: Uses filters flag/flagStatus eq 'notFlagged' and not categories/any() to only retrieve emails that are not yet categorized or flagged.
AI Agent1 (n8n node):
Function: Executes the core categorization logic using the LLM.
Key Configuration: Uses a comprehensive system prompt defining the AI's role and strict prioritization rules for categories like 'Action', 'Junk', and 'SaaS'. It mandates output in a specific JSON structure.
Ollama Chat Model1 (n8n node):
Function: Provides the LLM infrastructure, connecting the n8n workflow to the local Ollama server using the qwen2.5:14b model.
Markdown1 & varEmal1 (Data Sanitization n8n nodes):
Function: Cleans the raw HTML email body, removing unnecessary clutter, links, and special characters before sending the text to the AI, dramatically improving categorization accuracy.
varJSON1 (Set n8n node):
Function: Parses the AI output string into a JSON object. Crucially, it uses the continueErrorOutput setting, ensuring the n8n workflow does not halt if the AI generates slightly imperfect JSON.
Switch1 (Flow Control n8n node):
Function: Directs the execution path based on the primary category output by the AI Agent (e.g., routes 'receipt' emails to the receipt processing path).
Microsoft Outlook (Update/Move n8n nodes):
Function: Updates the email with the assigned category tags and then moves the message to the corresponding folder (e.g., Junk, Receipt, SaaS).
If1 (Conditional n8n node):
Function: For high-priority categories ('action', 'business'), it checks the isRead status before moving the email to the 'Actioned' archive, streamlining follow-up processes in this n8n template.

Related n8n Workflows

Free

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by

I’m Wayne, an AI, automation & low-code consultant, passionate about helping businesses unlock their potential through smart, practical solutions.

Featured*