Skip to main content

Automatic Gmail categorization and labeling with AI

Workflow preview

Workflow preview
100%
Automatic Gmail categorization and labeling with AI preview
Open on n8n.io

Important notice

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

1. Workflow Overview

This workflow contains community nodes that are only compatible with the self hosted version of n8n. Who is this for? If your inbox is full of unread emails, this workflow is for you. Instead of re...

Best for

  • Personal Productivity automation workflows
  • AI Summarization automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.set, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.outputparserstructured, n8n-nodes-base.scheduletrigger, @n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.gmail, n8n-nodes-base.switch, n8n-nodes-base.stickynote

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Matt Chong | n8n Creator.

Original n8n.io source

1.1 Workflow description

Title
Automatic Gmail categorization and labeling with AI
Workflow name
Automatic Gmail categorization and labeling with AI

This workflow contains community nodes that are only compatible with the self-hosted version of n8n.

Who is this for?

If your inbox is full of unread emails, this workflow is for you.
Instead of reading through them one by one, let AI do the sorting.
It reads your emails and flags only what needs action.

What does it solve?

This workflow reads your unread Gmail emails and uses AI to decide what’s important — and what’s not. It labels emails that need your attention, identifies receipts, and trashes everything else. No more manual reading. Just an inbox that uses AI to take care of itself.

How it works

  1. Every hour, the workflow runs automatically.
  2. It searches for unread emails in your Gmail inbox.
  3. For each email:
    • It extracts the content and sends it to OpenAI.
  4. The AI returns one of four labels: Action, Receipt, Informational or Spam.
  5. Based on the label:
    • Emails are marked with the appropriate label.
    • Or moved to trash it is spam.
  6. It marks the email as read once processed.

How to set up?

  1. Connect these services in your n8n credentials:
    • Gmail (OAuth2)
    • OpenAI (API key)
  2. Create the Gmail labels:
    • In your Gmail account, create these labels exactly as written:
      Action, Receipt, and Informational
    • The workflow will apply these labels based on AI classification.

How to customize this workflow to your needs

  • Change the AI prompt to detect more types of emails like Meeting or Newsletter.
  • Add more branches to the Switch node to apply custom logic.
  • Change the schedule to fit your workflow. By default, it runs every hour, but you can update this in the Schedule Trigger node.

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 - Edit Fields

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 2 - AI Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 2

Block 3 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.3

Block 4 - Schedule Trigger

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

Block 5 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 6 - Get All Unread Messages

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

Block 7 - Switch

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.2

Block 8 - OpenAI Fall Back Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 9 - Delete email

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

Block 10 - Mark email as read

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

Block 11 - Add label "Receipt" to email

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

Block 12 - Add label "Action" to email

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

Block 13 - Sticky Note

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

Block 14 - Sticky Note1

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

Block 15 - Sticky Note2

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

Block 16 - Sticky Note3

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

Block 17 - Add label "Informational" to email

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

3. Summary Table

Workflow Automatic Gmail categorization and labeling with AI
Complexity advanced
Nodes 17
Categories Personal Productivity, AI Summarization
Author Matt Chong | n8n Creator
Published 09 Jul 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/5820/5820.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 Automatic Gmail categorization and labeling with AI do?

This workflow contains community nodes that are only compatible with the self hosted version of n8n. Who is this for? If your inbox is full of unread emails, this workflow is for you. Instead of re...

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 Personal Productivity, AI Summarization use case.