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.
Download this n8n workflow template and start using it instantly.
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.
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.
qwen2.5:14b) is installed on your Ollama server.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.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.
This powerful n8n workflow automates daily ingestion of CVE and IOC threat feeds, applies custom AI logic for risk triage, and triggers incident response actions like email alerts, Google Sheets logging, and EDR isolation requests. Use this n8n template for compliant security operations.

Automate bug tracking by syncing Zendesk tickets tagged 'bug' into a centralized Google Sheets dashboard using this robust n8n workflow. Use this n8n template to streamline QA and support reporting.

Automate your entire content pipeline using this powerful n8n workflow. Manage blog ideas in Google Sheets, generate drafts with AI, and automatically publish to WordPress.

Use this advanced n8n workflow to generate, refine, and publish viral X (Twitter) threads using voice or text input via Telegram, powered by GPT. Features an approval loop.

Automate documentation syncing using this robust n8n workflow. Triggers on GitHub PR merges, summarizes changes with GPT-4o Mini, and notifies Slack teams instantly.

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







































