AI Email Classifier & Auto-Delete for Gmail Cleanup - n8n Workflow

Automate Gmail cleaning with this powerful n8n workflow. Use a specialized n8n node powered by AI to classify and automatically delete SPAM and marketing OFFER emails, ensuring a clean, focused inbox.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Business Owners: Who need to filter out noise and focus only on important customer communications.
Freelancers and Solopreneurs: Tired of cold emails and promotional offers cluttering their primary inbox.
n8n Automation Specialists: Looking for robust n8n templates integrating LangChain agents for complex text classification tasks.
Users Seeking a Clean Inbox: Anyone who wants an automated solution to handle low-value SPAM and OFFER emails.

Overview

Inbox clutter significantly reduces productivity. This specialized n8n workflow solves this by deploying an AI-powered email classification system. Instead of relying on basic keyword filtering, this n8n workflow utilizes a detailed system prompt within an OpenAI n8n node to accurately categorize emails into three classes: SPAM, OFFER, or IMPORTAND.

Only emails classified as SPAM or commercial OFFER are targeted for automatic deletion. This highly effective n8n template ensures that valuable messages, such as order confirmations, invoices, or personal inquiries, remain untouched, offering a highly efficient solution for maintaining a pristine Gmail inbox using n8n.

How it Works

This automation initiates using a reliable n8n trigger and follows a strict logical flow:


  1. Polling Initiation: The n8n workflow begins with the Gmail Trigger n8n trigger, which periodically (e.g., every hour) checks the connected Gmail inbox for new incoming messages.

  2. AI Classification: The newly retrieved email snippet is passed to the Validator of Email n8n node. This is a LangChain Agent that utilizes the powerful gpt-4.1-nano model through a dedicated OpenAI n8n node. It analyzes the content against predefined rules (distinguishing between SPAM, OFFER, and IMPORTAND) and returns a single-word classification.

  3. Conditional Check: The output of the AI is analyzed by the If n8n node. This node checks if the classification is either SPAM or OFFER.

  4. Deletion Action: If the condition is met (meaning the email is low-value), the n8n workflow proceeds to the Delate Email n8n node. This n8n node uses the unique message ID captured by the initial n8n trigger to permanently delete the email, completing the automated cleanup process.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON and import it directly into your self-hosted or cloud n8n instance using the 'New' > 'Import from JSON' option.

  2. Configure Gmail Credentials: The Gmail Trigger and Delate Email n8n nodes require Gmail OAuth2 credentials. Set up a connection, ensuring it has the necessary permissions to read and delete emails from your inbox.

  3. Configure OpenAI Credentials: The OpenAI Chat Model and Validator of Email n8n nodes require an OpenAI API Key credential. Ensure your API key is correctly configured and has access to run chat model requests.

  4. Activate the n8n workflow: After setting up all necessary credentials, save the n8n workflow and toggle the status to 'Active'. It is highly recommended to first test the n8n workflow manually before relying on its scheduled execution.

Node Details

Gmail Trigger n8n trigger: Functionally, this node acts as the starting point, polling your Gmail inbox hourly for new messages. It extracts critical metadata, including the message ID and snippet, which are essential for subsequent steps in the n8n workflow.
Validator of Email (LangChain Agent n8n node): This key n8n node is where the intelligence resides. It sends the email snippet to the AI for classification. The configuration uses a highly detailed system message to ensure accurate, single-word responses (SPAM, OFFER, or IMPORTAND). It is connected to the dedicated OpenAI Chat Model n8n node configured to use gpt-4.1-nano.
If n8n node: This is the core decision-making component of the n8n workflow. It uses a logical OR condition, checking if the output from the AI agent matches SPAM or OFFER to determine whether to proceed with deletion.
Delate Email (Gmail n8n node): Executed only if the email is deemed non-important. This n8n node performs the deletion operation using an expression to dynamically reference the email ID provided by the originating n8n trigger (={{ $('Gmail Trigger').item.json.id }}).

Related n8n Workflows

Free

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

AI Automation Expert | Web & Mobile App Integrator With 2+ years of experience, I build smart automations, web & mobile app workflows, and scalable platforms using tools like n8n, Make, and more. I help businesses reduce operational costs, save time, and scale faster with AI-powered solutions. For business enquiries, send me an email at [email protected]

Featured*