Automated Gmail Classification using AI Text Classifier - n8n Workflow

Use this advanced n8n workflow to automatically categorize and label incoming Gmail emails using OpenAI GPT-5. Simplify inbox management with powerful n8n automation and intelligent classification.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users overwhelmed by email volume needing smart inbox sorting.
n8n users looking for advanced AI-driven automation examples.
Developers seeking ready-made n8n templates for Gmail and OpenAI integration.
Anyone who wants to implement an intelligent email classification system without manual effort.

Overview

This powerful n8n workflow provides a sophisticated solution for achieving Inbox Zero through AI-driven organization. By leveraging the robustness of the n8n platform alongside the intelligence of the OpenAI GPT-5 model, this automation runs on a schedule defined by the n8n trigger, fetching recent emails and processing them. The core value of this n8n template is eliminating manual email sorting. Each incoming email is analyzed, categorized (e.g., High Priority, Personal, Promotions), and automatically assigned a corresponding Gmail label using a dedicated Gmail n8n node. This ensures that only the most critical messages rise to the top of your inbox, making this n8n workflow an essential tool for productivity. Setting up this n8n workflow transforms your email management from reactive to proactive.

How it Works


  1. The n8n trigger, configured as a Schedule Trigger, initiates the entire n8n workflow on a recurring basis (running every minute, based on the node configuration, designed to fetch data from the last few minutes).

  2. The Gmail - Get Emails n8n node runs, retrieving recent messages based on the defined time filter and limit (up to 10 emails from the last 5 minutes).

  3. The results are passed to the Loop Over Items n8n node, which ensures that each email item is processed individually to maintain classification accuracy across the entire batch.

  4. Inside the loop, the Label Classifier n8n node, connected to the OpenAI Chat Model, analyzes the combined email subject and body text. This critical n8n node uses predefined categories and descriptions to determine the correct classification (High Priority, Personal, or Promotions).

  5. Based on the classification output, one of the conditional Gmail n8n nodes is executed. For instance, if the classification is "High Priority," the Add Label (High Priority) n8n node is activated, applying the "IMPORTANT" label to the Gmail thread ID.

  6. The process efficiently loops back to handle the remaining emails, completing the execution of this robust n8n workflow and ensuring all new mail is labeled.

Installation Guide


  1. Import: Download the provided JSON and import it into your self-hosted or cloud n8n instance using the "New Workflow" -> "Import from JSON" option. This forms the base of your automated n8n workflow.

  2. Credentials: This n8n workflow requires two main credentials:

Gmail OAuth2: Connect your Gmail account so the workflow can read emails and apply labels.
OpenAI API Key: Set up credentials for the OpenAI integration to power the Text Classifier n8n node.

  1. Configuration: Review the Label Classifier n8n node settings to adjust the categories (and their detailed descriptions) to fit your specific inbox needs. Ensure the Add Label n8n nodes use the correct corresponding Gmail label IDs (which must exist in your Gmail account). You can add or remove label nodes as needed for your custom n8n templates.

  2. Activation: Once credentials and configurations are set, activate the Schedule Trigger n8n node to start the automated classification process. Your powerful new n8n workflow is now live.

Node Details

Schedule Trigger: This is the foundational n8n trigger, set to run the entire n8n workflow at regular intervals, ensuring continuous monitoring of the inbox. Key Configuration: Runs the workflow based on minute intervals.
Gmail - Get Emails: An essential Gmail n8n node responsible for fetching the raw email data. Function: Retrieves the last 10 email threads received within the previous 5 minutes. Key Configuration: Operation: getAll, includes dynamic filtering based on time.
Loop Over Items: A crucial flow control n8n node. Function: Splits the fetched batch of emails so that the AI classification and labeling steps are performed uniquely for every message item within the n8n workflow.
Label Classifier: A specialized n8n node leveraging AI for text classification. Function: Analyzes the concatenated subject and body of the email and categorizes it into one of the defined classes (High Priority, Personal, Promotions) using the linked OpenAI model. Key Configuration: Defines specific categories and detailed descriptions for accurate classification. This node requires the connection to the underlying LLM.
OpenAI Chat Model: The underlying large language model provider n8n node. Function: Provides the AI intelligence (configured to use GPT-5) required by the Label Classifier n8n node to analyze and categorize the email text accurately.
Add Label (High Priority), Add Label (Personal), Add Label (Promotions): Dedicated Gmail n8n node actions. Function: Applies the corresponding standard Gmail label (e.g., IMPORTANT, CATEGORY_PERSONAL) to the email thread based on the AI’s classification result, automating the final step of the n8n workflow. Key Configuration: Operation: addLabels, targets the dynamic threadId.

Related n8n Workflows

Free

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

I build scalable automation systems with n8n to help businesses save time and cut costs. 💼 n8n expert available for new projects 📩 [email protected]

Featured*