AI Email Triage and Auto-Archiving System - n8n Workflow

Automate Gmail inbox organization using an AI Agent. This n8n workflow categorizes emails, applies priority labels, auto-archives, and reports actions via Telegram.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users overwhelmed by their email inbox.
Automation specialists looking for advanced AI Agent examples in n8n.
Professionals needing a structured way to triage priority emails without manual sorting.
Individuals interested in advanced Gmail automation using n8n templates.

Overview

This sophisticated n8n workflow transforms chaotic email management into an automated, intelligent process. By leveraging the power of AI Agents integrated via OpenRouter, the solution filters your Gmail inbox, identifies critical, routine, or spam emails, and takes immediate action—labeling or archiving. This specific n8n workflow is designed to reduce decision fatigue and ensure that high-priority messages are instantly marked, while clutter is seamlessly archived. This automation can be initiated conveniently via a Telegram message, offering remote control over your inbox. This is a highly valuable addition to any user's library of production-ready n8n templates, showcasing advanced use of the n8n node structure for complex decision-making.

How it Works

The process begins when the n8n trigger is activated, either manually or via the dedicated Telegram n8n trigger.


  1. Fetch Inbox: The Gmail n8n node retrieves all messages currently labeled as INBOX.

  2. Filter Processed Mails: A Filter n8n node checks if emails have already been tagged (e.g., NotNeed or MustRead). Emails already processed are skipped, preventing unnecessary work for the AI.

  3. AI Triage (Categoriser): The core logic is handled by a LangChain Agent n8n node, powered by an OpenRouter Chat Model. This agent analyzes the subject, sender, and snippet of each email against predefined rules.

  4. Dynamic Action: Based on the analysis, the AI dynamically selects and uses either the mailarchiver (a Gmail Tool n8n node set to remove the INBOX label) or the maillabel_setter (a Gmail Tool n8n node set to apply custom labels like MustRead).

  5. Result Aggregation: The Aggregate n8n node collects the action reports generated by the Categoriser agent for every single email processed in this n8n workflow execution.

  6. Summary Generation (Reporter): A second LangChain Agent n8n node summarizes the collective actions taken, providing a clean overview of which emails were archived and which were labeled.

  7. Notification: Finally, the Telegram n8n node sends this summarized report back to the originating chat, confirming the successful execution of the n8n workflow.

Installation Guide

To use this n8n workflow effectively, follow these steps:


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

  2. Credential Setup: This n8n workflow requires three sets of credentials:

Gmail OAuth2: Configure access to your Gmail account. This is used by the 'Get mails in INBOX', mailarchiver, and maillabel_setter n8n node instances.
OpenRouter API: Set up credentials for OpenRouter to allow the LangChain Agent n8n node instances ('Categoriser' and 'Reporter') to access the underlying language models (e.g., openai/gpt-4.1-nano).
* Telegram API: Configure your Telegram Bot token for the Telegram Trigger and the final Telegram n8n node for receiving commands and sending reports.

  1. Webhook Activation: Ensure the Telegram trigger is active by setting up its webhook after defining the credentials.

  2. Customize AI Rules: Review the system message within the 'Categoriser' n8n node to customize the archiving and labeling rules (e.g., replacing [list up your rule1]) to match your specific email management needs.

  3. Test: Click the 'Test workflow' n8n trigger to verify all connections and logic are functioning correctly before activating the Telegram n8n trigger.

Node Details

Telegram Trigger: Acts as the primary n8n trigger, initiating the process upon receiving a command message from the configured bot.
Get mails in INBOX (Gmail n8n node): Retrieves all messages currently in the INBOX. Key Configuration: operation: getAll, filters: labelIds: [INBOX].
Filter processed (Filter n8n node): Essential for efficiency, this n8n node checks if the email's existing labels already include 'NotNeed' or 'MustRead', ensuring only new emails pass through.
Categoriser (LangChain Agent n8n node): The core decision-maker. It uses the OpenRouter Chat Model n8n node to determine whether to archive the email or apply a priority label. It executes the downstream Gmail Tool n8n nodes dynamically.
mailarchiver (Gmail Tool n8n node): Used by the AI Agent to archive emails deemed unnecessary. Key Configuration: operation: removeLabels, targeting the INBOX label.
mail
label_setter (Gmail Tool n8n node): Used by the AI Agent to apply specified labels (e.g., 'MustRead'). Key Configuration: operation: addLabels, dynamically pulling label IDs from the AI's output.
Reporter (LangChain Agent n8n node): Summarizes the aggregated results of the email processing run using a separate OpenRouter Chat Model n8n node.
Telegram (Telegram n8n node): The final action, sending the processed summary report back to the user who activated the n8n workflow.

Related n8n Workflows

Free

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

Featured*