Automatic Outlook Email Organization using Advanced AI - n8n Workflow

Use this powerful n8n workflow to automatically categorize and sort incoming Outlook emails using advanced AI models like DeepSeek. Enhance productivity with this ready-to-use n8n template.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Freelancers or consultants who receive a high volume of varied client, project, or SaaS vendor emails.

  • Technical professionals seeking to automate email management and filing.

  • Users looking for advanced, AI-driven solutions to manage Microsoft Outlook inboxes.

  • n8n users who want an advanced example of integrating AI agents with email services.

Overview

Managing a high-volume professional inbox can be time-consuming, especially when emails require precise categorization and filing. This sophisticated n8n workflow provides a solution by automating this entire process using an advanced Language Model (LLM).

This n8n automation starts by polling your Outlook inbox for new, uncategorized emails. It then retrieves all your existing Outlook folder names to use as the definitive list of categories. The email content is cleaned and passed to an AI Agent n8n node, which intelligently determines the best fit category and subcategory.

Finally, this powerful n8n template uses the categorization result to automatically update the email's category tag in Outlook and move it to the corresponding folder, ensuring your inbox remains clean and organized without manual intervention. This flow leverages the versatility of the n8n platform to link complex AI logic directly to your daily productivity tools.

How it Works

The entire process is initiated by the n8n trigger:


  1. Scheduled Polling: The Schedule Trigger n8n node runs every minute, initiating the check for new emails.

  2. Fetch Uncategorized Emails: The RecievedEmail (Microsoft Outlook n8n node) retrieves up to one unread email that has not been flagged and currently lacks any assigned categories.

  3. Data Preparation: The email body is converted to Markdown and then rigorously cleaned by the varEmal1 n8n node, removing HTML, links, and excessive whitespace to ensure high-quality input for the AI.

  4. Category Context Retrieval: Two sequential Microsoft Outlook nodes (Get many folders) retrieve all existing Outlook folder names. These names are summarized and cleaned by the Summarize and Code nodes, creating a comma-separated list of potential categories.

  5. AI Categorization (Primary): The AI Agent1 n8n node, connected to an OpenRouter Chat Model, receives the cleaned email and the definitive list of categories (your folder names). The AI performs a detailed analysis to classify the email and outputs the result as a structured JSON object containing the determined category and subCategory.

  6. Error Fallback: If the primary AI call fails, the flow attempts a secondary categorization via the fallback AI Agent n8n node.

  7. JSON Validation & Parsing: The varJSON1 n8n node extracts and validates the AI's JSON output. If parsing fails, the error is logged via Catch Errors1, and the flow continues to the next item.

  8. Folder Matching & Action: The Get many folders1 node retrieves the folders again. The If node checks if the AI-assigned category matches an existing folder display name. If a match is found, the n8n workflow proceeds.

  9. Outlook Update: The Update Category n8n node applies the AI-determined category tags (primary and subCategory) to the Outlook message.

  10. Email Filing: The Move Folder n8n node moves the email to the specific folder corresponding to the AI's primary category, thus completing the automated filing.

Installation Guide

To deploy this powerful n8n template, follow these steps:


  1. Import: Copy the provided n8n workflow JSON and import it into your n8n instance.

  2. Credentials Setup:

Microsoft Outlook: You must set up OAuth2 credentials for the Microsoft Outlook n8n node. Ensure the account has the necessary permissions to read emails, retrieve folders, update categories, and move messages.
OpenRouter: Set up API key credentials for the OpenRouter n8n node. This service provides access to various advanced LLMs (like DeepSeek), ensuring robust categorization quality.

  1. Configuration: Review the RecievedEmail n8n node parameters. Ensure the foldersToInclude filter is set correctly for your target inbox folder.

  2. Activation: Once credentials are set, activate the n8n workflow. The Schedule Trigger will begin checking your inbox at the defined interval (default: every 1 minute).

Node Details

Schedule Trigger (n8n trigger): Initiates the n8n workflow on a recurring schedule, set to run every 1 minute to check for new emails.
RecievedEmail (Microsoft Outlook n8n node): The initial step that polls the inbox. It is specifically configured to only fetch emails that are not read, not flagged, and critically, do not have any existing categories (not categories/any()).
varEmal1 (Set n8n node): Performs complex data manipulation using an expression to clean the email body, stripping HTML and extraneous characters, standardizing the text for optimal AI consumption.
Get many folders / Summarize / Code: These nodes work together to dynamically retrieve all available Outlook folder display names and compile them into a single list, which serves as the allowed category list for the AI Agent.
AI Agent1 (n8n node): The core intelligence of this n8n workflow. It uses the OpenRouter Chat Model to analyze the email against the list of available categories (folder names) and returns a structured JSON classification.
varJSON1 (Set n8n node): Crucial for post-processing the AI output. It uses a regex expression to ensure that only the valid JSON structure is extracted from the AI's text response, providing reliability.
If (n8n node): A logic gate that ensures the AI's categorized output matches an actual, existing folder name in Outlook before attempting to move the email.
Update Category (Microsoft Outlook n8n node): Applies the category and subCategory determined by the AI directly to the email metadata in Outlook.


  • Move Folder (Microsoft Outlook n8n node): The final action, which files the categorized email into the corresponding folder, completing the automation cycle using this n8n template.

Related n8n Workflows

Free

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

Featured*