Gmail Email Auto-Classifier using GPT-4 Mini - n8n Workflow

Use this efficient n8n workflow to automatically categorize incoming Gmail messages into categories like Business, Sales, or Meetings using an advanced OpenAI Chat Model and apply specific actions.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Productivity Enthusiasts: Individuals seeking to minimize manual email sorting time.
Small Business Owners: Users who need to quickly identify and prioritize important business communications while deleting spam/cold sales emails.
n8n Developers: Those looking for practical examples of integrating LangChain text classification and the OpenAI Chat Model within a functional n8n workflow.
Technical Users: Anyone wanting to deploy a powerful, custom email sorting system using a robust n8n template.

Overview

Managing high volumes of incoming email can be a significant drag on productivity. This specialized n8n workflow solves this problem by leveraging cutting-edge AI to instantly categorize and manage your inbox. Instead of manually reviewing every email, this n8n template automatically processes messages as they arrive, classifying them into predefined groups like 'Business,' 'Meetings,' or 'Sales.' For example, sales or cold emails are instantly deleted, while business-critical communications are flagged as 'IMPORTANT.' This entire operation is powered by a reliable n8n node structure, ensuring seamless integration between your Gmail account and the OpenAI API. Deploying this n8n automation means reclaiming hours spent on inbox management.

How it Works

The entire process begins with a dedicated n8n trigger, the Gmail Trigger node, which constantly monitors your inbox for new messages, polling every minute.


  1. Trigger: When a new email is detected, the n8n trigger extracts the email's subject and snippet (a short preview of the body).

  2. AI Classification: The data is passed to the Text Classifier n8n node, which uses the linked OpenAI Chat Model (specified as gpt-4.1-mini) to determine the category of the message. The defined categories are 'Business,' 'Sales,' 'Meetings,' and 'Random.'

  3. Conditional Routing: Based on the output of the classification, the flow routes the email thread to one of the following action branches:

If Business: The Business n8n node adds the IMPORTANT label to the email thread.
If Sales: The Cold Emails n8n node automatically deletes the email thread from Gmail.
If Meetings: The Meetings n8n node applies the YELLOW_STAR label to ensure it is immediately noticeable.
If Random: The flow is routed to a No Operation n8n node, halting further action for unclassified emails.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


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

  2. Set up Gmail Credentials: Locate the Gmail Trigger and the three subsequent Gmail action nodes. You must configure or select existing Gmail OAuth2 credentials that grant n8n permission to read emails, add labels, and delete threads.

  3. Set up OpenAI Credentials: Locate the OpenAI Chat Model n8n node. You must set up or select your OpenAI API credentials. Ensure your API key is active and configured correctly.

  4. Activate the n8n workflow: Once all credentials are set up, switch the workflow status from 'Inactive' to 'Active'. The Gmail trigger will now start polling your inbox.

Node Details

Gmail Trigger: This is the initial n8n trigger that starts the automation. It is configured to poll your Gmail inbox every minute, initiating the workflow whenever a new email is received.
OpenAI Chat Model: Configured as the underlying language model for classification. This n8n node specifies the use of the gpt-4.1-mini model, providing fast and accurate categorization capabilities.
Text Classifier: A LangChain-based n8n node that takes the email Subject and Snippet as input. It utilizes the connected OpenAI model to classify the text into one of four categories: Business, Sales, Meetings, or Random. This is the core logic engine of the n8n workflow.
Business (Gmail Node): If the classification result is 'Business,' this n8n node performs the action of adding the IMPORTANT label to the corresponding Gmail thread ID.
Cold Emails (Gmail Node): If classified as 'Sales,' this critical n8n node is configured to delete the entire email thread, effectively filtering out unsolicited cold messages.
Meetings (Gmail Node): If classified as 'Meetings,' this n8n node adds the YELLOW_STAR label, helping to visually prioritize scheduling-related communications.


  • No Operation, do nothing: Acts as the termination point for emails classified as 'Random,' ensuring they are processed without modifying the Gmail state.

Related n8n Workflows

Free

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

I design and build custom no-code and low-code automations using n8n to help businesses save hours of manual work, streamline operations, and create clean, scalable workflows.

Featured*