Animated data flow diagram

AI Outlook Email Categorization Agent with Ollama

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

Microsoft Outlook Ollama Langchain

Overview

Unlock Automated Email Organization with this AI Agent

This AI-driven n8n workflow acts as your personal email assistant for Microsoft Outlook. It diligently fetches new, unflagged, and uncategorized emails from your inbox (or a specified folder). The core of this agent is its email categorization ability, powered by a local Ollama Large Language Model (LLM) you configure (e.g., qwen2.5:14b as used in the template).

First, the agent sanitizes the email content, stripping HTML and unnecessary characters to prepare clean data for the AI. Then, it passes the subject, sender, and cleaned body to the Ollama model via an n8n AI Agent node. Based on your custom instructions and defined categories (e.g., 'Action', 'Junk', 'Receipt', 'SaaS', 'Community', 'Business', 'Other'), the AI determines the primary category and an optional subcategory for each email, along with its reasoning.

Finally, the workflow automatically applies these categories within Outlook and moves the email to a corresponding pre-configured folder, keeping your inbox organized and ensuring important emails are prioritized. For emails categorized as 'Action' or 'Business', it can also check if they've been read and move them to an 'Actioned' folder if so.

Key Features & Benefits

  • AI-Powered Categorization: Leverages local Ollama LLMs for intelligent email sorting, providing privacy and control over your data.
  • Outlook Integration: Seamlessly reads, updates (categories), and moves emails within your Microsoft Outlook account.
  • Customizable Logic: Define your own email categories, subcategories, and the AI's decision-making process through editable prompts in the AI Agent node.
  • Targeted Processing: Intelligently filters emails to only process unflagged and uncategorized items, avoiding redundant work.
  • Content Sanitization: Prepares email content for optimal AI analysis by removing HTML, markdown clutter, and special characters.
  • Automated Filing: Moves categorized emails to designated Outlook folders, decluttering your inbox and improving focus.
  • Actionable Insights: The AI provides a brief analysis for each categorization decision, helping you understand its choices.
  • Error Robustness: Includes error handling to ensure continuous operation even if some AI responses need adjustment.

Use Cases

  • B2C E-commerce: Automatically sort customer inquiries, order confirmations (receipts), and supplier communications in Outlook.
  • B2B SaaS: Triage support emails, filter partnership proposals, and organize product update notifications from vendors.
  • Solopreneurs/Founders: Keep your Outlook inbox tidy by auto-filing client communications, invoices, and industry newsletters.
  • Heads of Automation: Implement a robust, local AI-powered email processing system for Outlook users to boost team efficiency and maintain data privacy.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • Microsoft Outlook credentials with permissions to read, update, and move emails.
  • An Ollama instance running and accessible by n8n, with a suitable chat model downloaded (e.g., qwen2.5:14b or your preferred model).
  • n8n Langchain nodes installed (usually included, but verify @n8n/n8n-nodes-langchain).

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. Configure the Microsoft Outlook23 node (labeled 'Get All Emails'):
    • Set up your Microsoft Outlook credentials.
    • Verify or adjust the foldersToInclude to target your main inbox or specific folders.
    • Review the custom filter (flag/flagStatus eq 'notFlagged' and not categories/any()) to ensure it meets your needs.
  4. Configure the Ollama Chat Model1 node:
    • Enter the Base URL of your Ollama instance.
    • Ensure the model field (e.g., qwen2.5:14b) matches a model you have downloaded and available in Ollama.
    • Adjust temperature or other options as needed.
  5. Customize categories in the varID & Category1 Set node:
    • Edit the category field's string value (e.g., "action", "junk", "receipt", ...) to reflect your desired primary categories. These are passed to the AI Agent's prompt.
  6. Review and customize prompts in the AI Agent1 node:
    • Modify the System Message to refine the AI's role, categorization rules, and priorities.
    • Adjust the Text (user prompt) if you change the input data structure or want to give different instructions.
    • Ensure the categories mentioned in the prompts align with those defined in the 'varID & Category1' node and the 'Switch1' node.
  7. Configure the Switch1 node:
    • Review the routing rules. Each rule should correspond to a category output by the AI Agent (e.g., 'junk', 'receipt').
    • Add, remove, or modify rules and their Output Key names to match your categories.
  8. For each output path of the 'Switch1' node, configure the subsequent Microsoft Outlook nodes:
    • Update Message Nodes (e.g., 'Microsoft Outlook12'): Ensure the categories expression correctly maps the AI's category and subCategory output to Outlook categories. The template uses: ={{ [$('varJSON1').first().json.output.category, $('varJSON1').first().json.output.subCategory].filter(item => item && item.trim() !== "").map(item => item.charAt(0).toUpperCase() + item.slice(1)) }}.
    • Move Message Nodes (e.g., 'Microsoft Outlook10'): Select the correct target Folder (folderId) in Outlook for each category.
  9. Review the logic in the If1 node (checks isRead) and the subsequent Microsoft Outlook Move Message1 node (moves to 'Actioned' folder). This is typically for 'action' or 'business' categories. Adjust the target folder or conditions as needed.
  10. Test the workflow with a few sample emails using the 'When clicking ‘Test workflow’' manual trigger.
  11. Once satisfied, replace the manual trigger with a schedule trigger (e.g., 'Cron' or 'Interval') for continuous, automated operation. Activate the workflow.

Tags:

AI AgentEmail AutomationOllamaNLPProductivityMicrosoft OutlookInbox ManagementLangchainLocal LLM

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation