Skip to main content

Auto-label incoming Gmail messages with AI nodes

Workflow preview

Workflow preview
100%
Auto-label incoming Gmail messages with AI nodes 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 uses AI to analyze the content of every new message in Gmail and then assigns specific labels, according to the context of the email. Default configuration of the workflow includes 3 ...

Best for

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

Tools used

n8n-nodes-base.stickynote, n8n-nodes-base.gmailtrigger, n8n-nodes-base.gmail, @n8n/n8n-nodes-langchain.chainllm, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.outputparserstructured, n8n-nodes-base.set, n8n-nodes-base.splitout

Source and attribution

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

Original n8n.io source

1.1 Workflow description

Title
Auto-label incoming Gmail messages with AI nodes
Workflow name
Auto-label incoming Gmail messages with AI nodes

This workflow uses AI to analyze the content of every new message in Gmail and then assigns specific labels, according to the context of the email.

Default configuration of the workflow includes 3 labels:

  • „Partnership” - email about sponsored content or cooperation,
  • „Inquiry” - email about products, services,
  • „Notification” - email that doesn't require response.

You can add or edit labels and descriptions according to your use case.

🎬 See this workflow in action in my YouTube video about automating Gmail.

How it works?

Gmail trigger performs polling every minute for new messages (you can change the trigger interval according to your needs). The email content is then downloaded and forwarded to an AI chain.

💡 The prompt in the AI chain node includes instructions for applying labels according to the email content - change label names and instructions to fit your use case.

Next, the workflow retrieves all labels from the Gmail account and compares them with the label names returned from the AI chain. Label IDs are aggregated and applied to processed email messages.

⚠️ Label names in the Gmail account and workflow (prompt, JSON schema) must be the same.

Set up steps

  1. Set credentials for Gmail and OpenAI.
  2. Add labels to your Gmail account (e.g. „Partnership”, „Inquiry” and „Notification”).
  3. Change prompt in AI chain node (update list of label names and instructions).
  4. Change list of available labels in JSON schema in parser node.
  5. Optionally: change polling interval in Gmail trigger (by default interval is 1 minute).

If you like this workflow, please subscribe to my YouTube channel and/or my newsletter.

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 - Sticky Note

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

Block 2 - Sticky Note1

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

Block 3 - Sticky Note2

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

Block 4 - Sticky Note4

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

Block 5 - Sticky Note5

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

Block 6 - Sticky Note6

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

Block 7 - Sticky Note7

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

Block 8 - Sticky Note8

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

Block 9 - Gmail trigger

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

Block 10 - Get message content

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

Block 11 - Assign labels for message

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

Block 12 - OpenAI Chat

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

Block 13 - JSON Parser

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

Block 14 - Set label values

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

Block 15 - Get all labels

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

Block 16 - Split out assigned labels

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

Block 17 - Merge corresponding labels

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

Block 18 - Aggregate label IDs

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

Block 19 - Add labels to message

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

3. Summary Table

Workflow Auto-label incoming Gmail messages with AI nodes
Complexity advanced
Nodes 19
Categories Ticket Management, AI Summarization
Author Oskar
Published 27 Mar 2024

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/2197/2197.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-label incoming Gmail messages with AI nodes do?

This workflow uses AI to analyze the content of every new message in Gmail and then assigns specific labels, according to the context of the email. Default configuration of the workflow includes 3 ...

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.