AutomationFlowsAI & RAG › Categorise and Label Gmail Emails with Gpt-4o and Openai

Categorise and Label Gmail Emails with Gpt-4o and Openai

ByZac Nielsen @itszacnielsen on n8n.io

Automatically organise your Gmail inbox using AI. This workflow categorises every incoming email and applies Gmail labels, keeping only important emails in your inbox while filing everything else automatically.

Event trigger★★★★☆ complexityAI-powered12 nodesOpenAIGmailGmail Trigger
AI & RAG Trigger: Event Nodes: 12 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #13221 — 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": "v8RrApVEwyIAADJqW-k-N",
  "name": "Categorise and label emails automatically with AI using Gmail and OpenAI",
  "tags": [],
  "nodes": [
    {
      "id": "dc9fb4ee-c544-4bd0-a959-4ce44258ade1",
      "name": "Categorize Email",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        784,
        128
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are my helpful, intelligent administrative assistant."
            },
            {
              "content": "=You are an email categorisation assistant.\n\nCategorise each email into ONE of the following labels:\n- Action Required (needs my direct response or decision)\n- Admin/Receipts (invoices, receipts, subscription confirmations, account notifications)\n- Call Recordings (meeting recordings, call summaries, Zoom/Fathom/Fireflies recordings, video call links)\n- Client Communication (existing clients, project updates, support requests)\n- Files (shared documents, file transfers, Google Drive/Dropbox shares, attachment-focused emails)\n- Leads/Prospects (potential clients showing genuine interest in services)\n- Newsletters (subscribed content, industry updates, educational emails)\n- Notifications (automated alerts, app notifications, system updates)\n- People Selling Me Stuff (cold pitches, sales outreach, vendors trying to sell services)\n- Sponsorship Requests (affiliate offers, partnership proposals, sponsorship pitches)\n- Test (test emails, internal testing, QA emails)\n- Vendors (existing vendor communication, not sales pitches)\n\nRules:\n- If someone is pitching something unsolicited \u2192 People Selling Me Stuff\n- If someone wants affiliate/sponsorship/partnership \u2192 Sponsorship Requests\n- If it's a genuine business inquiry about YOUR services \u2192 Leads/Prospects\n- If it's from an existing client \u2192 Client Communication\n- If it contains a call/meeting recording or summary \u2192 Call Recordings\n- If the primary purpose is sharing/sending files \u2192 Files\n- If it's clearly a test or QA email \u2192 Test\n- When in doubt between sales pitch vs legitimate \u2192 People Selling Me Stuff\n\nReturn JSON only:\n{\"category\":\"exact label name here\"}"
            },
            {
              "content": "Let's Collaborate with AI SEO Agent That Saves Time and Costs\n\nHey [Name],\n\nI'm [Sender] from [Company], where we're passionate about the transformative impact of AI on digital marketing and content strategies.\n\nI came across your video on \"[Video Title]\", and I love how you simplify automation and provide actionable strategies for building online businesses. We have recently launched [Product], an innovative AI tool designed to simplify and optimise workflows.\n\nHere's what [Product] offers:\n- Saves up to 80% of time on research\n- Provides actionable insights through integrations\n- Optimises visibility across platforms\n\nI'd love to explore a potential collaboration with you to showcase [Product] to your audience. Let me know if this resonates and I'd be happy to share more details.\n\nBest regards,"
            },
            {
              "role": "assistant",
              "content": "={\"category\":\"Sponsorship Requests\"}"
            },
            {
              "content": "=For the attention of [Recipient Name]\n\nHi [Name], I hope you're having a great day so far!\n\nI love the look & feel of your Channel. Your content is great.\n\nMy team and I have taken a look at your Social media and we are very confident we can help you get 15-20 High-Ticket clients signed every single month.\n\nThe best part is... if we don't deliver, you don't pay! We work on a 100% pay on results basis.\n\nBy the way, this isn't an automated message. I'm a real human! I recorded a quick video to introduce myself.\n\nWe've already helped other businesses add $30k-$40K per month.\n\nI would love the opportunity to learn more about your business, challenges and goals to see if there's a fit.\n\nWould you be interested in having a call this week so we can discuss?\n\nThanks,\n[Sender]\n\np.s. - when I say pay on results, I really mean it! No performance = no money out of your pocket.\n"
            },
            {
              "role": "assistant",
              "content": "{\"category\":\"People Selling Me Stuff\"}"
            },
            {
              "content": "Amazing Videos\n\nThanks for the reply [Name], \n\nI've been diving into your videos and find your content truly amazing. I genuinely believe this is exactly what I've been searching for. My plan is to follow your guidance step by step, and I'm hopeful that it will lead to success.\n\nI'm incredibly grateful for individuals like you who dedicate their time to helping others succeed. I look forward to the opportunity to connect in the future, and I hope to share some major wins with you when that time comes.\n\nThank you again for everything.\n\nBest regards,\n\n[Sender]"
            },
            {
              "role": "assistant",
              "content": "={\"category\":\"Action Required\"}"
            },
            {
              "content": "=subject: {{ $json.Subject }}\n\ntext: {{ $json.snippet }}"
            }
          ]
        },
        "jsonOutput": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "4a4ab82f-740a-4496-9436-e3e63129745a",
      "name": "Not Worthwhile",
      "type": "n8n-nodes-base.filter",
      "position": [
        1168,
        128
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "fe013229-2567-4904-b321-fce8844aec93",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.message.content.category }}",
              "rightValue": "Action Required"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "75007181-40d7-480f-bd6f-d51c0c735117",
      "name": "Get Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1392,
        128
      ],
      "parameters": {
        "filters": {
          "q": "=subject:\"{{ $('Gmail Trigger').item.json.Subject }}\" ",
          "sender": "={{ $('Gmail Trigger').item.json.From }}"
        },
        "operation": "getAll"
      },
      "typeVersion": 2.1
    },
    {
      "id": "de17d21c-de13-4cb5-b053-29b8b5117554",
      "name": "Add to folder",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1824,
        128
      ],
      "parameters": {
        "labelIds": "=YOUR_LABEL_ID",
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2.1
    },
    {
      "id": "5d5ba1b4-8c5e-4a4c-868d-a0b7de14ef95",
      "name": "Remove from Inbox",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1600,
        128
      ],
      "parameters": {
        "labelIds": [
          "INBOX"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "removeLabels"
      },
      "typeVersion": 2.1
    },
    {
      "id": "b6f42d1a-b557-49df-99bb-3301f07400c9",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        560,
        128
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "1a79dae4-ff6b-4feb-afd4-d7cc4eb56ae2",
      "name": "Get many labels",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1648,
        384
      ],
      "parameters": {
        "resource": "label",
        "returnAll": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "b7c67a1e-6d1c-43d7-8c42-942086c76d3b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 480,
        "height": 536,
        "content": "## Categorise and label emails automatically with AI using Gmail and OpenAI\n\nThis workflow automatically categorises incoming emails using AI and applies Gmail labels to organize your inbox. Emails that don't require action are automatically filed away.\n\n### How it works\n1. Gmail monitors your inbox for new emails every minute\n2. AI analyzes each email and assigns a category\n3. Non-urgent emails are removed from inbox and labeled\n4. Action-required emails stay in your inbox\n\n### Setup steps\n1. Connect Gmail account (click Gmail nodes to authenticate)\n2. Add OpenAI API key (click Categorize Email node)\n3. Create Gmail labels for your categories\n4. Run 'Get many labels' node to find label IDs\n5. Update 'Add to folder' node with your label IDs\n6. Customize categories in the AI prompt (optional)"
      },
      "typeVersion": 1
    },
    {
      "id": "204f04b1-59a6-4e7f-b331-f5699afc7ac9",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 288,
        "content": "### \ud83d\udce5 Step 1: Receive & Analyze\nNew emails trigger the workflow automatically. AI reads the content and decides which category fits best."
      },
      "typeVersion": 1
    },
    {
      "id": "1bc7ace6-1b67-4a14-aedb-0f0c97e4a6c4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        32
      ],
      "parameters": {
        "color": 7,
        "width": 880,
        "height": 256,
        "content": "### \ud83d\udccb Step 2: Filter & File\nEmails that don't need immediate attention are automatically moved out of inbox and organized with the correct label."
      },
      "typeVersion": 1
    },
    {
      "id": "5951c932-864b-4b5c-9184-8ac976b1b619",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1136,
        320
      ],
      "parameters": {
        "color": 6,
        "width": 784,
        "height": 240,
        "content": "### \u2699\ufe0f Setup: Gmail Labels\n\n**Before running this workflow:**\n1. Create labels in Gmail for your categories\n2. Click 'Get many labels' node \u2192 Execute\n3. Copy the label IDs from the output\n4. Open 'Add to folder' node\n5. Replace 'YOUR_LABEL_ID' with your actual label ID\n\n**Tip:** The label ID looks like \"Label_123456789\""
      },
      "typeVersion": 1
    },
    {
      "id": "98794dca-7144-493b-a65a-ee372cdaed65",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        336
      ],
      "parameters": {
        "color": 6,
        "width": 576,
        "height": 272,
        "content": "### \u2699\ufe0f Optional: Customize Categories\n\n**Want different email categories?**\nOpen 'Categorize Email' node \u2192 Edit the system message\n\n**You can:**\n- Add/remove categories from the list\n- Change the classification rules\n- Add more example emails to improve accuracy\n\n**Tip:** The AI learns from examples. Add 2-3 sample emails for each category you want."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "52461f8d-6a25-4b44-ac38-61d27846e264",
  "connections": {
    "Get Email": {
      "main": [
        [
          {
            "node": "Remove from Inbox",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Categorize Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Not Worthwhile": {
      "main": [
        [
          {
            "node": "Get Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Categorize Email": {
      "main": [
        [
          {
            "node": "Not Worthwhile",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove from Inbox": {
      "main": [
        [
          {
            "node": "Add to folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

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

About this workflow

Automatically organise your Gmail inbox using AI. This workflow categorises every incoming email and applies Gmail labels, keeping only important emails in your inbox while filing everything else automatically.

Source: https://n8n.io/workflows/13221/ — 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 delivers a complete, enterprise-grade Gmail automation system designed for high-volume teams. It classifies incoming emails, applies labels, generates AI-powered responses, and routes me

Gmail, OpenAI, Telegram +3
AI & RAG

Domain Outbound Machine is an n8n workflow designed to fully automate the domain sales process: lead generation, email extraction, personalized outreach, and automated email sending. It also stores ex

Google Sheets, HTTP Request, Gmail +1
AI & RAG

Monitor YouTube channels, fetch stats, classify videos as viral (≥ 1000 likes) or normal, and auto‑generate LinkedIn/email summaries with GPT‑4. Deliver via Gmail or SMTP. Clear node names, examples,

RSS Feed Read, HTTP Request, OpenAI +1
AI & RAG

This workflow automatically converts incoming Gmail messages into structured support tickets using AI classification. It assigns categories, generates a unique ticket ID, stores data in PostgreSQL, as

Gmail, Text Classifier, Lm Ollama +2
AI & RAG

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

Gmail Trigger, Write Binary File, Information Extractor +3