AI-Powered Gmail Labeling with Gemini 2.5 Pro - n8n Workflow

Use this powerful n8n workflow to automatically classify and label incoming Gmail emails using Gemini 2.5 Pro. Leverage this n8n template for precise inbox management.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users drowning in emails who need automated categorization.
n8n experts looking for advanced AI-driven email management solutions.
Technical users wanting to see how the n8n Code node maps data between AI output and service IDs.
Professionals seeking a ready-to-use n8n template for Google services and LLMs.

Overview

Managing a busy inbox manually is inefficient. This specialized n8n workflow solves the problem by automating the classification of new, unread emails. It leverages the power of the Gemini 2.5 Pro model to analyze the email subject and snippet, determine the most suitable existing Gmail label, and instantly apply it. Unlike static filtering, this dynamic solution ensures highly accurate categorization based on context. This powerful n8n template starts with an n8n trigger watching your inbox and ends with a perfectly filed email. The beauty of this n8n workflow is that it dynamically pulls your existing labels, so you never need to update the n8n node configuration when you create a new label, ensuring a resilient n8n workflow.

How it Works


  1. Trigger Event: The n8n workflow initiates using the Gmail Trigger n8n node, which constantly monitors your inbox for new unread emails.

  2. Label Sync: Immediately after the n8n trigger fires, the workflow fetches a comprehensive list of all existing Gmail labels (including their IDs) using the Get many labels n8n node.

  3. Data Preparation: The data is aggregated, and the Edit Fields n8n node prepares a comma-separated list of all label names, which acts as the mandatory classification list for the AI.

  4. AI Classification: The Message a model n8n node (using Gemini 2.5 Pro) receives the email content, along with the strict list of allowed labels. The AI analyzes the email and returns only the required label names, ensuring precision because it only selects from your existing labels.

  5. ID Mapping: A custom Code n8n node takes the comma-separated label names returned by the AI and maps them back to their unique Gmail Label IDs using the list fetched in Step 2. This crucial step prepares the data for the final action.

  6. Label Application: Finally, the Add label to message n8n node uses the mapped IDs to apply the correct label(s) to the original email message in Gmail, completing the automated n8n workflow.

Installation Guide


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

  2. Set up Gmail Credentials: Locate the Gmail Trigger, Get many labels, and Add label to message n8n nodes. Configure or select your Gmail OAuth2 credentials for all three nodes to grant the n8n workflow access to your email account and labels.

  3. Set up Gemini Credentials: Locate the Message a model n8n node. Configure or select your Google Gemini API credentials.

  4. Activate: Ensure the n8n workflow is active. It will now run according to the schedule set by the n8n trigger (default: every minute for unread emails). This n8n template is ready for immediate use.

Node Details

Gmail Trigger (n8n trigger): The starting point of this n8n workflow. It monitors for new emails, specifically configured to look only for unread messages.
Get many labels (Gmail n8n node): Retrieves a list of all custom and default labels in your Gmail account (returnAll: true). This is crucial for providing the AI with a controlled, accurate list of classification options.
Aggregate (n8n node): Combines the email data from the trigger with the label data, ensuring the label list is available in the subsequent nodes.
Edit Fields (Set n8n node): Creates the labelList variable containing all fetched label names, formatted as a comma-separated string for optimal prompt injection into the AI model.
Message a model (Google Gemini n8n node): Uses models/gemini-2.5-pro for classification. The system message strictly enforces that the output must be a comma-separated list of existing labels, preventing incorrect or invented classifications.
Code (n8n node): Performs the necessary data transformation. It parses the AI's text output and dynamically converts the predicted label names into the necessary unique Gmail labelIds required by the final Gmail n8n node.


  • Add label to message (Gmail n8n node): The final action, applying the dynamically determined labelIds to the email identified by the messageId retrieved from the initial n8n trigger. This is a standard Gmail n8n node configured for the addLabels operation.

Related n8n Workflows

Free

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

Featured*