← All N8N workflows
AI & researchAgentGmail ToolGmail TriggerOpenAI Chat ModelMemory Buffer Window

Gmail labelling agent

Configured with Agent, Gmail Tool, Gmail Trigger, OpenAI Chat Model, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
TriggerGmail TriggerGmail TriggerAI & modelsOpenAI Chat Model1OpenAI Chat ModelMessagingGmail - read labelsGmail ToolMessagingGmail - get messageGmail ToolMessagingGmail - add label tomessageGmail ToolMessagingGmail - create labelGmail ToolAI & modelsGmail labelling agentAgentData storeWindow Buffer MemoryMemory Buffer WindowWaitWaitWait

Node categories in this workflow

  • Trigger
  • AI & models
  • Messaging
  • Data store
  • Wait

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
OpenAI Chat Model1AI & modelsOpenAI Chat ModelSee node parameters
Gmail - read labelsMessagingGmail Toollabel
Gmail - get messageMessagingGmail Toolget
Gmail - add label to messageMessagingGmail TooladdLabels
Gmail - create labelMessagingGmail Toollabel / create
Gmail labelling agentAI & modelsAgentSee node parameters
Window Buffer MemoryData storeMemory Buffer WindowSee node parameters
WaitWaitWaitSee 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

Gmail labelling agent

Objective: Automatically categorize incoming emails based on existing Gmail labels or create a new label if none match.

Tools:

  • Get message
  • Read all labels
  • Create label
  • Assign label to message

Instructions:

Label Matching:

Analyze the email's subject, sender, recipient, keywords, and content. Compare with existing Gmail labels to find the most relevant match. Label Assignment:

Assign the email to the most appropriate existing label.` Remove the inbox label if the email is of less importance (like ads, promotions, aka "Reclame"), keep normal and important emails in the inbox. If no suitable label exists, create a new label based on the existing labels. Try reusing existing labels as much as possible. Always create a label as a sublabel, if no label applies, if the main label already exists, create the new label under the existing label, if no main label exists, create the label AI and create the new label under this label. Label Creation:

Ensure new labels align with the structure of existing ones, including capitalization, delimiters, and prefixes. Examples:

If the email subject is "Project Alpha Update," assign to [Project Alpha] if it exists. For "New Vendor Inquiry," create "Vendor Inquiry" if no relevant label exists. Outcome: Emails are consistently categorized under the appropriate or newly created labels, maintaining Gmail's organizational structure.

Gmail trigger

Gmail trigger

Poll Gmail every x minutes, trigger when a new email is received.

  • Gmail API
Gmail labelling agent

Gmail labelling agent

  • Read the message
  • Read existing labels
  • Create a new label if needed
  • Assign label to message

Objective: Automatically categorize incoming emails based on existing Gmail labels or create a new label if none match.

Tools:

  • Get message
  • Read all labels
  • Create label
  • Assign label to message

Instructions:

Label Matching:

Analyze the email's subject, sender, recipient, keywords, and content. Compare with existing Gmail labels to find the most relevant match. Label Assignment:

Assign the email to the most appropriate existing label.` Remove the inbox label if the email is of less importance (like ads, promotions, aka "Reclame"), keep normal and important emails in the inbox. If no suitable label exists, create a new label based on the existing labels. Try reusing existing labels as much as possible. Always create a label as a sublabel, if no label applies, if the main label already exists, create the new label under the existing label, if no main label exists, create the label AI and create the new label under this label. Label Creation:

Ensure new labels align with the structure of existing ones, including capitalization, delimiters, and prefixes. Examples:

If the email subject is "Project Alpha Update," assign to [Project Alpha] if it exists. For "New Vendor Inquiry," create "Vendor Inquiry" if no relevant label exists. Outcome: Emails are consistently categorized under the appropriate or newly created labels, maintaining Gmail's organizational structure.

Gmail API

Gmail API

  • Add credentials
OpenAI

OpenAI

  • Add credentials
Gmail labelling agent

Gmail labelling agent

Purpose and structure

This folder contains the Gmail labelling agent workflow. Its executable nodes use agent, gmailTool, gmailTrigger, lmChatOpenAi, memoryBufferWindow, wait. 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/Stickynote/1353_Stickynote_Gmail_Send_Triggered.json MIT; preserve source notices.

More in AI & research