AutomationFlowsAI & RAG › Label Incoming Gmail Messages with Google Gemini and Telegram Alerts

Label Incoming Gmail Messages with Google Gemini and Telegram Alerts

ByYuvraj Soni @yuvraj on n8n.io

This workflow polls Gmail for new emails, uses Google Gemini via an n8n AI text classifier to categorize each message by subject and snippet, and automatically applies the matching Gmail label, sending a Telegram alert if classification errors occur. Checks Gmail every minute…

Event trigger★★★★☆ complexityAI-powered23 nodesText ClassifierGmailTelegramGmail TriggerGoogle Gemini Chat
AI & RAG Trigger: Event Nodes: 23 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #16621 — we link there as the canonical source.

This workflow follows the Gmail → Gmail Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "cs0PnDbTjcSmekSXJEipW",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "AI-Powered Gmail Label Automation",
  "tags": [],
  "nodes": [
    {
      "id": "45831688-18eb-4c85-b38f-eac73914b0bc",
      "name": "Text Classifier",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "onError": "continueErrorOutput",
      "position": [
        -1488,
        880
      ],
      "parameters": {
        "options": {},
        "inputText": "=Subject: {{ $json.Subject }}\nEmail Body:{{ $json.snippet }}",
        "categories": {
          "categories": [
            {
              "category": "Personal",
              "description": "Emails from friends, family members, or personal contacts that are not related to business, banking, shopping, or automated notifications."
            },
            {
              "category": "Job",
              "description": "Emails related to job opportunities, recruitment, interviews, job applications, offers, career updates, hiring platforms, or professional networking."
            },
            {
              "category": "Study Related",
              "description": "Emails from educational institutions, online learning platforms, certification providers, or training services. This includes course updates, assignments, certificates, newsletters, webinars, and learning resources."
            },
            {
              "category": "Bank ",
              "description": "Emails from banks or financial institutions related to accounts, transactions, statements, payments, credit/debit cards, loans, or financial alerts."
            },
            {
              "category": "Social ",
              "description": "Emails from social media platforms or online communities, including notifications, messages, mentions, friend requests, comments, followers, or account updates."
            },
            {
              "category": "OTP ",
              "description": "Emails containing one-time passwords (OTP), verification codes, authentication codes, or security codes used for login, account verification, or transactions."
            },
            {
              "category": "Misc",
              "description": "Any email that does not clearly belong to any of the above categories."
            }
          ]
        }
      },
      "executeOnce": false,
      "notesInFlow": false,
      "retryOnFail": false,
      "typeVersion": 1.1,
      "alwaysOutputData": false
    },
    {
      "id": "0057d948-3f9c-4c35-b09a-88a460192ed4",
      "name": "Personal",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1088,
        224
      ],
      "parameters": {
        "labelIds": [
          "Label_4955454057144185119"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "e68aa8c8-a5ee-4af0-a083-b08f19f264b8",
      "name": "Study related",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1088,
        416
      ],
      "parameters": {
        "labelIds": [
          "Label_2750201160708242693"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ea05e5cf-adae-4fed-9e95-0e681e7ee4ad",
      "name": "Bank related",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1088,
        608
      ],
      "parameters": {
        "labelIds": [
          "Label_3462277956554809458"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "efbd5a62-727b-462f-9bef-ff02b0a64bf1",
      "name": "Social Message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1088,
        1184
      ],
      "parameters": {
        "labelIds": [
          "Label_7207251993891335439"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ce455090-071c-4359-b663-9c50f76c6962",
      "name": "OTP",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1088,
        1376
      ],
      "parameters": {
        "labelIds": [
          "Label_6988279425733606549"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "5bb93de8-0acb-4286-9e20-285fa5d7d581",
      "name": "Misc",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1088,
        800
      ],
      "parameters": {
        "labelIds": [
          "Label_614923790413803230"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "19458c80-4ec2-4250-ab0a-fbd4945ac849",
      "name": "Job",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1088,
        992
      ],
      "parameters": {
        "labelIds": [
          "Label_873597841588403440"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "823c2ac9-6efe-4f19-aac7-84927cb46626",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -640,
        896
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "00f2950e-a0eb-4152-89e0-a60964df3a10",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2720,
        96
      ],
      "parameters": {
        "width": 672,
        "height": 656,
        "content": "# AI-Powered Gmail Email Classification\n\nThis workflow automatically classifies incoming Gmail emails using Google Gemini AI and applies the appropriate Gmail label based on the email content.\n\n## Features\n\n- Monitors new Gmail emails\n- Uses AI to classify email content\n- Automatically applies Gmail labels\n- Sends Telegram notifications (optional)\n- Includes basic error handling\n\n## Categories\n\n- Personal\n- Job\n- Study\n- Bank\n- Social\n- OTP\n- Misc\n\nThis template is fully customizable. You can add new categories, modify AI prompts, or replace Telegram with Slack, Discord, Email, or any other supported service."
      },
      "typeVersion": 1
    },
    {
      "id": "9bd0408d-b4ea-4f84-98a5-52616bc1aec0",
      "name": "Personal Message",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -864,
        224
      ],
      "parameters": {
        "text": "You Got New Personal Message",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "84b946bf-0359-4523-bae1-ea477864aa22",
      "name": "Study realated",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -864,
        416
      ],
      "parameters": {
        "text": "You Got New Study Related Message",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7e626bdf-6b10-4252-9172-a967e4fc58dd",
      "name": "Bank Related",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -864,
        608
      ],
      "parameters": {
        "text": "You Got New Bank Message",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "447c74c4-f0d0-41f6-8765-308c76e9ef8c",
      "name": "MISC",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -864,
        800
      ],
      "parameters": {
        "text": "You Got New MISC Message",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "65deffad-74e3-423f-9462-e68cc35d6b73",
      "name": "JOB",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -864,
        992
      ],
      "parameters": {
        "text": "You Got New Job Message",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "3cc5ccdd-7fe7-435a-aabc-2ec3c57404a2",
      "name": "Social Message Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -864,
        1184
      ],
      "parameters": {
        "text": "Social Message",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b5a933e6-98c4-4950-abb3-9eee546eac37",
      "name": "OTP1",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -864,
        1376
      ],
      "parameters": {
        "text": "OTP",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b4e58f18-dea2-44bd-bbaf-5f98d3ab63fb",
      "name": "Error Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        -896,
        1632
      ],
      "parameters": {
        "text": "Error in Gmail Workflow",
        "chatId": "123456",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "0f2cdac8-c117-49cc-b6b3-efbe65640086",
      "name": "Gmail Node",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1680,
        976
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.4
    },
    {
      "id": "871bc6c7-6947-44f1-9aca-e12216a994cb",
      "name": "AI Chat Model Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1488,
        1328
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "31f4d0a7-9a04-4dcb-bac9-7d23138e3a55",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2720,
        784
      ],
      "parameters": {
        "width": 512,
        "height": 320,
        "content": "# Setup Guide\n\nBefore activating the workflow:\n\n1. Connect your Gmail OAuth2 credentials.\n2. Connect your Google Gemini API credentials.\n3. (Optional) Connect your Telegram Bot credentials.\n4. Create the Gmail labels used in this workflow and update the Gmail nodes with your own labels.\n\nAfter completing these steps, activate the workflow to start automatically organizing incoming emails."
      },
      "typeVersion": 1
    },
    {
      "id": "92e45eb6-9cbe-4e27-aa2f-dba426540f08",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2720,
        1136
      ],
      "parameters": {
        "width": 432,
        "height": 272,
        "content": "# How It Works\n\n1. Gmail Trigger watches for new incoming emails.\n2. Google Gemini analyzes the email subject and snippet.\n3. The AI classifies the email into the most appropriate category.\n4. The corresponding Gmail label is applied.\n5. An optional Telegram notification is sent.\n6. If an error occurs, an error notification can be triggered."
      },
      "typeVersion": 1
    },
    {
      "id": "7ffeaa6e-09c5-46cf-b507-c744c77c74c5",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2720,
        1440
      ],
      "parameters": {
        "width": 496,
        "height": 336,
        "content": "# Customization\n\nYou can easily customize this workflow by:\n\n- Adding or removing email categories\n- Updating the AI classification prompt\n- Changing Gmail labels\n- Disabling Telegram notifications\n- Replacing Telegram with Slack, Discord, Microsoft Teams, or Email\n- Extending the workflow with additional automations such as Google Sheets, Notion, Airtable, or CRM integrations"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "86aa45a1-8f89-4cb6-82d3-96fc0e7a45d3",
  "nodeGroups": [],
  "connections": {
    "JOB": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Job": {
      "main": [
        [
          {
            "node": "JOB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OTP": {
      "main": [
        [
          {
            "node": "OTP1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MISC": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Misc": {
      "main": [
        [
          {
            "node": "MISC",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OTP1": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          },
          {
            "node": "Personal",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Personal": {
      "main": [
        [
          {
            "node": "Personal Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Node": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Bank Related": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Bank related": {
      "main": [
        [
          {
            "node": "Bank Related",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Study related": {
      "main": [
        [
          {
            "node": "Study realated",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Telegram": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Social Message": {
      "main": [
        [
          {
            "node": "Social Message Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Study realated": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "Personal",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Job",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Study related",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Bank related",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Social Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OTP",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Misc",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Personal Message": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Chat Model Gemini": {
      "ai_languageModel": [
        [
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Social Message Telegram": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This workflow polls Gmail for new emails, uses Google Gemini via an n8n AI text classifier to categorize each message by subject and snippet, and automatically applies the matching Gmail label, sending a Telegram alert if classification errors occur. Checks Gmail every minute…

Source: https://n8n.io/workflows/16621/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

This workflow showcases various useful Gmail search, filter, and AI categorization operations and generates a knowledge graph for your mail using the InfraNodus GraphRAG API, which you can use to reve

HTTP Request, Google Gemini Chat, Gmail +3
AI & RAG

3277. Uses gmailTrigger, textClassifier, lmChatGoogleGemini, emailSend. Event-driven trigger; 16 nodes.

Gmail Trigger, Text Classifier, Google Gemini Chat +3
AI & RAG

This n8n workflow is designed to intelligently manage incoming emails and automatically send personalized responses based on the content. It classifies emails using LangChain's Text Classifier, sends

Gmail Trigger, Text Classifier, Google Gemini Chat +3
AI & RAG

This project presents an intelligent email management system powered by advanced artificial intelligence. It utilizes Google's Gemini 2.0 AI model to automatically categorize incoming emails into quer

Gmail Trigger, Text Classifier, Google Gemini Chat +3
AI & RAG

This n8n template automatically classifies incoming emails (Sales, Support, Internal, Finance, Promotions) and routes them to a dedicated OpenAI LLM Agent for processing. Depending on the category, th

OpenAI, Gmail, Text Classifier +16