Automate Outlook Email Categorization Using AI with n8n

Struggling with sorting a cluttered Outlook inbox? This n8n workflow auto-categorizes unread and unflagged Outlook emails using AI, saving hours of manual work by tagging and moving emails based on their contents.
microsoftOutlook
agent
manualTrigger
+8
Workflow Identifier: 2094
NODES in Use: Manual Trigger, Sticky Note, LangChain AI Agent, Microsoft Outlook, SplitInBatches, Markdown, Set, Filter, If, Switch, Merge
Automate Outlook email categorization with n8n and AI

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow automatically finds Outlook emails that are not flagged and have no categories yet assigned.
It cleans email content and uses AI to sort emails into groups like Action, Junk, Receipt, SaaS, Community, Business, or Other.
Then it updates Outlook with the right categories and moves emails to matching folders.
This saves lots of time and stops mistakes in manual sorting.


Who should use this workflow

This is good for users who get many emails daily in Outlook and want to reduce time spent on sorting.
It suits people who want clear categories without doing manual tagging.
You need some basic skills in n8n and access to Microsoft Outlook API.


Tools & services used

  • Microsoft Outlook API: To fetch, update, and move emails.
  • n8n Workflow Automation: To run and connect all steps.
  • Ollama LangChain AI Agent (Qwen2.5 14B Model): To analyze email content and decide categories.

Beginner step-by-step: How to use this workflow in n8n production

Step 1: Import the workflow

  1. Download the workflow file using the Download button on this page.
  2. In the n8n editor, choose “Import from File” and upload the downloaded workflow.

Step 2: Configure credentials and settings

  1. Go to each Microsoft Outlook node and add or verify Outlook API credentials.
  2. Open the AI Agent1 node and ensure the Ollama API Key is set properly.
  3. Update Outlook folder IDs if needed to match your mailbox folders.
  4. Check the varID & Category1 node to confirm or change category names if desired.

Step 3: Test the workflow

  1. Run the workflow manually using the Manual Trigger node.
  2. Watch the execution and check if emails are categorized and moved as expected.

Step 4: Activate for production

  1. Change the trigger from manual to scheduled or webhook depending on needs.
  2. Save and activate the workflow.
  3. Monitor runs on n8n and review logs for errors.

Beginner users can start breaking down and understanding each step if they want, but this guide helps quickly get the workflow running with minimum hassle.


Workflow inputs, processing, and outputs explained

Inputs

  • Outlook emails that have no flags and no categories.
  • Email fields like subject, sender, body (HTML), and importance.

Processing

  • Filter emails for uncategorized and unflagged only.
  • Handle emails one at a time for stable processing.
  • Clean email body from HTML to plain text using the Markdown node.
  • Sanitize important email fields to remove HTML tags, images, and special characters.
  • Use AI agent with a strict prompt to analyze and assign category.
  • Parse AI output JSON safely for category results.
  • Route emails based on category to update Outlook categories and move folders.
  • Check if email was read; move to “Actioned” folder if yes.
  • Merge all processed emails and repeat until done.
  • Catch and log any errors without stopping overall workflow.

Outputs

  • Outlook emails with new categories assigned.
  • Emails moved to folders based on assigned category.
  • Error logs for failed email processing.

Common edge cases and failures

  • AI output not valid JSON stops category parsing.
  • Outlook API failures when messageId is incorrect or access lacks permissions.
  • Emails already read are treated differently to avoid duplicate actions.
  • Timeouts or rate limits on AI calls may slow batches.

Error handling nodes log issues but let other emails process.


Customization ideas

  • Add new categories in varID & Category1 node if more types needed.
  • Adjust AI model temperature to make classification more strict or creative.
  • Rename Outlook folders in move nodes to match your mailbox exactly.
  • Change Outlook query filters to handle flagged emails or specific folders.
  • Extend AI prompt for sentiment, priority, or deeper content analysis.

Customizations allow tuning the workflow to fit unique mailbox setups or user preferences.


Example AI prompt for categorization

Below prompt is used in the AI Agent1 node to ask AI how to categorize each email.

=Categorise the following email

{{ $('varEmal1').first().json.toJsonString() }}


Ensure your final output is valid JSON with no additional text or token in the following format:
{
  "subject": "SUBJECT_LINE",
  "category": "CATEGORY",
  "subCategory": "SUBCATEGORY", //use sparingly
  "analysis": "ANALYSIS_REASONING"
}

This prompt forces the AI to reply only with clean JSON, avoiding parsing errors downstream.


Important notes on running and hosting n8n with this workflow

For best results run the workflow inside a stable n8n environment with internet access to Outlook and Ollama APIs.

Using self-host n8n offers more control over credentials, better security, and option to monitor logs tightly.

Make sure API keys and folder IDs are kept up to date for smooth operation.


Summary of benefits

→ Saves hours by automating email sorting.
→ Guarantees consistent and clear email categories.
→ Reduces mistakes from manual sorting.
→ Keeps inbox organized by moving emails into correct folders.
→ Catches errors and continues working without stopping.


Automate Outlook email categorization with n8n and AI

Visit through Desktop to Interact with the Workflow.

Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.
Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.

Frequently Asked Questions

Download the workflow file. In n8n editor, import it using “Import from File.” Then add required API credentials and update folder IDs. Test manually once and activate the workflow.
The workflow may fail to parse AI results. Use strict prompts and the JSON parse node to catch errors. Error handling nodes log these issues and allow other emails to process.
No, the workflow is designed only for unflagged and uncategorized emails. To handle flagged emails, modify the Outlook filter query accordingly.
All data stays within the user’s Outlook account and n8n instance. Secure API keys and host n8n properly, such as by using self-host n8n for better security.

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.