Skip to main content

Auto-classify Gmail emails with AI and apply labels for inbox organization

Workflow preview

Workflow preview
100%
Auto-classify Gmail emails with AI and apply labels for inbox organization preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Who is this for? Professionals and individuals who receive high volumes of emails , those who want to automatically organize their Gmail inbox using AI classification . What problem is this workflo...

Best for

  • Ticket Management automation workflows
  • AI Summarization automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.lmchatopenrouter, n8n-nodes-base.aggregate, n8n-nodes-base.merge, @n8n/n8n-nodes-langchain.chainllm, n8n-nodes-base.gmailtrigger, n8n-nodes-base.gmail, n8n-nodes-base.code

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Alex Dunlop.

Original n8n.io source

1.1 Workflow description

Title
Auto-classify Gmail emails with AI and apply labels for inbox organization
Workflow name
Auto-classify Gmail emails with AI and apply labels for inbox organization

Who is this for?

Professionals and individuals who receive high volumes of emails, those who want to automatically organize their Gmail inbox using AI classification.

What problem is this workflow solving?

Manual email sorting is time-consuming and inconsistent. This workflow automatically categorizes incoming emails into 8 predefined labels (To respond, FYI, Comment, Notification, Meeting update, Awaiting reply, Actioned, Marketing) to help maintain inbox zero and prioritize responses.

What this workflow does

  • Monitors Gmail for new incoming emails
  • Uses AI to analyze email content and classify into appropriate categories
  • Automatically applies the corresponding Gmail label
  • Runs on a schedule to process emails consistently

Setup

Prerequisites
  • n8n instance (cloud or self-hosted)
  • Gmail account with API access enabled
  • Access to an LLM provider (OpenAI, Anthropic Claude, or similar)

Step-by-Step

  1. Configure Gmail Credentials
  2. Create Gmail Labels
  3. Configure LLM Chain
  4. Set Email Polling Schedule
  5. Test the Workflow
Create Gmail Labels

Before running the workflow, create these 8 labels in your Gmail account:

  1. To respond
  2. FYI
  3. Comment
  4. Notification
  5. Meeting update
  6. Awaiting reply
  7. Actioned
  8. Marketing

How to customize this workflow to your needs

Modify Classification Categories

To change the email categories, update two places:

In the AI prompt (Basic LLM Chain node):

1. Your new category - Description of what emails fit here
2. Another category - Description
[... continue with your categories]

In Gmail labels: Create corresponding labels in your Gmail account with the exact same names and numbering.

Adjust Classification Rules

The AI prompt contains specific rules for each category. To modify:

  • Edit the "Key classification rules" section in the LLM prompt
  • Add examples of emails that should go into each category
  • Specify edge cases and how they should be handled

Change Email Sources

Currently monitors all incoming emails. To filter specific emails:

In the Gmail Trigger node, add filters such as:

You can also change this use Outlook

Modify Polling Frequency

  • More frequent: Add multiple poll times (e.g., 9 AM, 12 PM, 6 PM)
  • Less frequent: Change to once daily or weekly
  • Real-time: Switch to webhook-based triggering (requires Gmail API setup)

I choose daily for cost.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - OpenRouter Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenRouter - lmChatOpenRouter
Config choices
Version 1

Block 2 - Aggregate Gmail Messages

Type / Role
n8n-nodes-base.aggregate - aggregate
Config choices
Version 1

Block 3 - Merge Labels & Messages

Type / Role
n8n-nodes-base.merge - merge
Config choices
Version 3.1

Block 4 - Classify Email with AI

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.7

Block 5 - New Gmail Email Received

Type / Role
n8n-nodes-base.gmailTrigger - gmailTrigger
Config choices
Version 1.2

Block 6 - Fetch Available Gmail Labels

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 7 - Map Label Names to IDs

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 8 - Apply Classification Label

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

3. Summary Table

Workflow Auto-classify Gmail emails with AI and apply labels for inbox organization
Complexity intermediate
Nodes 8
Categories Ticket Management, AI Summarization
Author Alex Dunlop
Published 11 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4876/4876.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Auto-classify Gmail emails with AI and apply labels for inbox organization do?

Who is this for? Professionals and individuals who receive high volumes of emails , those who want to automatically organize their Gmail inbox using AI classification . What problem is this workflo...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Ticket Management, AI Summarization use case.