← All N8N workflows
AI & researchAggregateChain LLMGmailGmail TriggerOpenAI Chat Model

Add AI labels to Gmail messages

Configured with Aggregate, Chain LLM, Gmail, Gmail Trigger, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
TriggerGmail triggerGmail TriggerMessagingGet message contentGmailTransformSet label valuesEdit FieldsMessagingGet all labelsGmailTransformSplit out assignedlabelsSplit OutTransformMerge correspondinglabelsMergeTransformAggregate label IDsAggregateMessagingAdd labels to messageGmailAI & modelsAssign labels formessageChain LLMTransformJSON ParserOutput Parser StructuredAI & modelsOpenAI ChatOpenAI Chat Model

Node categories in this workflow

  • Trigger
  • Messaging
  • Transform
  • AI & models

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
Gmail triggerTriggerGmail TriggerSee node parameters
Get message contentMessagingGmailget
Set label valuesTransformEdit FieldsSee node parameters
Get all labelsMessagingGmaillabel
Split out assigned labelsTransformSplit OutSee node parameters
Merge corresponding labelsTransformMergeSee node parameters
Aggregate label IDsTransformAggregateSee node parameters
Add labels to messageMessagingGmailaddLabels
Assign labels for messageAI & modelsChain LLMSee node parameters
JSON ParserTransformOutput Parser StructuredSee node parameters
OpenAI ChatAI & modelsOpenAI Chat ModelSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • gmailOAuth2
  • openAiApi

Workflow notes

Add AI labels to Gmail messages

Add AI labels to Gmail messages

With this workflow you can automatically set labels for your Gmail message according to its content.

In this workflow available are 3 labels: "Partnership", "Inquiry" and "Notification". Feel free to adjust labels according to your needs.

Please remember to set label names both in your Gmail account and workflow.

⚠️ Note

⚠️ Note

  1. Complete video guide for this workflow is available on my YouTube.
  2. Remember to add your credentials and configure nodes (covered in the video guide).
  3. If you like this workflow, please subscribe to my YouTube channel and/or my newsletter.

Thank you for your support!

Gmail Trigger

Gmail Trigger

Receive data from Gmail about new incoming message.

⚠️ Set polling interval according to your needs.

### JSON schema

JSON schema

Edit JSON schema and label names according to your needs.

⚠️ Label names in system prompt and JSON schema should be the same.

Merge labels

Merge labels

Combine labels retrieved from Gmail account and assigned by AI together.

Aggregarte labels and add to message

Aggregarte labels and add to message

Create array of label IDs and add to the desired email message in Gmail.

Get message content

Get message content

Based on Gmail message ID retrieve body content of the email and pass it to AI chain.

Assign labels

Assign labels

Let the AI decide which labels suit the best content of the message.

⚠️ Remember to edit system prompt - modify label names and instructions according to your needs.

Add AI labels to Gmail messages

Add AI labels to Gmail messages

Purpose and structure

This folder contains the Add AI labels to Gmail messages workflow. Its executable nodes use aggregate, chainLlm, gmail, gmailTrigger, lmChatOpenAi, merge, outputParserStructured, set, splitOut. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

Gmail trigger

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Aggregate/1324_Aggregate_Gmail_Send_Triggered.json MIT; preserve source notices.

More in AI & research