AutomationFlowsAI & RAG › Automatically Label Gmail Emails with Gpt-5 Classification

Automatically Label Gmail Emails with Gpt-5 Classification

ByAbideen Bello @bideen on n8n.io

This workflow automatically monitors your Gmail inbox and uses OpenAI's GPT model to intelligently classify incoming emails into four key categories: High Priority - Urgent emails requiring immediate attention from executives, clients, or stakeholders Promotion - Marketing…

Event trigger★★★☆☆ complexityAI-powered8 nodesGmail TriggerText ClassifierOpenAI ChatGmail
AI & RAG Trigger: Event Nodes: 8 Complexity: ★★★☆☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #7759 — 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": "iPhhNVPzleZr44YK",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Inbox Management Agent",
  "tags": [],
  "nodes": [
    {
      "id": "240f8e93-87f3-4185-bc12-9b82ab43ce9c",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -336,
        -128
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c6b683ca-49c4-41b2-aace-9cc434164460",
      "name": "Text Classifier",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        -112,
        -128
      ],
      "parameters": {
        "options": {},
        "inputText": "={{ $json.text }}",
        "categories": {
          "categories": [
            {
              "category": "High Priority",
              "description": "Emails that require immediate attention or quick response, often from executives, key clients, or internal stakeholders. These usually involve time-sensitive issues, deadlines, or escalations. Keywords/phrases to look for: \u201curgent,\u201d \u201cASAP,\u201d \u201cimmediate response,\u201d \u201cdeadline,\u201d \u201ccritical,\u201d \u201cimportant matter.\u201d"
            },
            {
              "category": "Promotion",
              "description": "Emails related to marketing campaigns, sales offers, product launches, or event invitations. Typically sent in bulk and often contain discounts, new features, or company news. Keywords/phrases to look for: \u201cspecial offer,\u201d \u201cdiscount,\u201d \u201climited time,\u201d \u201cnew product,\u201d \u201cwebinar,\u201d \u201csale,\u201d \u201cexclusive invite.\u201d"
            },
            {
              "category": "Finance/Billing",
              "description": "Emails dealing with payments, invoices, receipts, or financial records. May come from vendors, clients, or internal finance teams. Usually involve transactions, balances, or account updates. Keywords/phrases to look for: \u201cinvoice,\u201d \u201cpayment due,\u201d \u201cbilling,\u201d \u201creceipt,\u201d \u201caccount statement,\u201d \u201crefund,\u201d \u201ctransaction.\u201d"
            },
            {
              "category": "Customer Support",
              "description": "Emails from customers seeking help, troubleshooting, or service requests. Often include questions, complaints, or technical issues that require a response or resolution. Keywords/phrases to look for: \u201cissue,\u201d \u201cnot working,\u201d \u201chelp,\u201d \u201csupport needed,\u201d \u201cerror,\u201d \u201cproblem with,\u201d \u201ccan you fix.\u201d"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "572a1a99-1193-4128-9073-43b5a8a11d11",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -40,
        160
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5",
          "cachedResultName": "gpt-5"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "02ca20f3-241e-42df-8969-0c97119b77f8",
      "name": "High Priority",
      "type": "n8n-nodes-base.gmail",
      "position": [
        240,
        -416
      ],
      "parameters": {
        "labelIds": [
          "Label_2050230922550608961"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "66943ca1-563f-426a-8d81-10be52294555",
      "name": "Promotion",
      "type": "n8n-nodes-base.gmail",
      "position": [
        240,
        -224
      ],
      "parameters": {
        "labelIds": [
          "Label_4137435394166770583",
          "CATEGORY_PROMOTIONS"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "32916943-2fc8-4b25-b986-bbc5ba64df7a",
      "name": "Finance/Billings",
      "type": "n8n-nodes-base.gmail",
      "position": [
        240,
        -32
      ],
      "parameters": {
        "labelIds": [
          "Label_123317652592217245"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "ec3002b3-20a6-44c0-855f-43788eedbd4c",
      "name": "Customer Support",
      "type": "n8n-nodes-base.gmail",
      "position": [
        240,
        160
      ],
      "parameters": {
        "labelIds": [
          "Label_3866679317291552912"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "fb064df0-b84c-466c-b773-7e71e4fcd863",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1008,
        -1280
      ],
      "parameters": {
        "width": 1520,
        "height": 2064,
        "content": "# Smart Gmail inbox organization with OpenAI classification\n\n## Who's it for\nThis template is perfect for busy professionals, customer service teams, and small business owners who receive high volumes of email and struggle to keep their Gmail inbox organized. If you're spending too much time manually sorting emails or missing important messages in the clutter, this AI-powered solution will transform your email management.\n\n## How it works\nThis workflow automatically monitors your Gmail inbox and uses OpenAI's GPT model to intelligently classify incoming emails into four key categories:\n - High Priority - Urgent emails requiring immediate attention from executives, clients, or stakeholders\n - Promotion - Marketing emails, sales offers, product launches, and event invitations\n - Finance/Billing - Invoices, receipts, payment notifications, and financial records\n - Customer Support - Help requests, troubleshooting queries, and service-related issues\n  \nOnce classified, emails are automatically labeled in Gmail using the appropriate tags, making it easy to filter, search, and prioritize your communications.\n\n## How to set up\n### Requirements\n - Gmail account with OAuth2 access enabled\n - OpenAI API key with GPT model access\n - Custom Gmail labels created for each category\n\n### Step-by-step setup\n 1. Create Gmail Labels\n  - In Gmail, create these labels: \"High Priority\", \"Promotion\", \"Finance/Billing\", \"Customer Support\"\n  - Note the label IDs (you'll need to replace the hardcoded ones in the workflow)\n 2. Configure Credentials\n  - Add your Gmail OAuth2 credentials in n8n\n  - Add your OpenAI API credentials\n 3. Update Label IDs\n  - Replace the hardcoded label IDs in each Gmail node with your actual label IDs\n  - You can find label IDs by testing the Gmail node or using Gmail API\n 4. Adjust Classification Rules\n  - Review the Text Classifier categories and modify descriptions to match your specific needs\n  - Add or remove categories as required\n 5. Set Polling Frequency\n  - The workflow is set to check every minute - adjust based on your email volume\n\n\n## How to customize the workflow\n### Modify Categories\n - Edit the Text Classifier node to add/remove email categories\n - Update category descriptions to better match your business context\n - Add corresponding Gmail nodes for new categories\n\n### Change AI Model\n - Switch from GPT-5 to GPT-4 or GPT-3.5-turbo based on your needs and budget\n - Adjust the model parameters in the OpenAI Chat Model node\n\n### Add Actions Beyond Labeling\n  - **Star important** emails by adding a Gmail \"star\" action for high priority items\n  - **Forward to team members** using additional Gmail send nodes\n  - **Create calendar events**  from meeting requests using Google Calendar integration\n  - **Log to spreadsheet**  for email analytics using Google Sheets\n\n### Advanced Filtering\n  - Add Gmail filter conditions to the trigger (sender, subject patterns, etc.)\n  - Include/exclude specific email addresses or domains\n  - Set up different polling schedules for different email types\n\n### Notification Options\n  - Add Slack notifications for high priority emails\n  - Send SMS alerts using Twilio for critical messages\n  - Create tickets in your support system for customer inquiries\n\n### Security considerations\n  - Never hardcode API keys in the workflow - always use n8n's credential system\n  - Review OpenAI's data usage policies for email content processing\n  - Consider data retention policies for processed email content\n  - Test thoroughly with non-sensitive emails first\n\n### Troubleshooting tips\n  - Classification accuracy: Fine-tune category descriptions if emails are being misclassified\n  - Rate limits: Monitor OpenAI API usage to avoid hitting rate limits with high email volumes\n  - Gmail quotas: Be aware of Gmail API quotas when processing large volumes\n  - Label sync: Allow time for Gmail labels to sync across devices and clients\n"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "874dd28f-0458-49bd-9e50-f23fd049c08a",
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "High Priority",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Promotion",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Finance/Billings",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Customer Support",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "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 automatically monitors your Gmail inbox and uses OpenAI's GPT model to intelligently classify incoming emails into four key categories: High Priority - Urgent emails requiring immediate attention from executives, clients, or stakeholders Promotion - Marketing…

Source: https://n8n.io/workflows/7759/ — 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

E-mail Assistant Agent. Uses gmailTrigger, textClassifier, gmail, lmChatOpenAi. Event-driven trigger; 29 nodes.

Gmail Trigger, Text Classifier, Gmail +6
AI & RAG

This workflow is ideal for: Customer support teams looking to reduce manual response time SaaS companies that frequently receive product inquiries E-commerce stores with common customer questions abou

OpenAI Chat, Output Parser Structured, Google Sheets Tool +5
AI & RAG

This workflow automates analyzing Gmail threads and drafting AI-powered replies with the new model Anthropic Sonnet 4.5.

Gmail Trigger, Gmail, OpenAI Chat +3
AI & RAG

Since Gmail inboxes can quickly become cluttered, this workflow provides an automated AI-based email classification system. It listens for new emails, categorizes them using an AI classifier, applies

Gmail Trigger, Text Classifier, Agent +3
AI & RAG

Gmail Googlecalendartool. Uses stickyNote, lmChatOpenAi, gmail, gmailTrigger. Event-driven trigger; 10 nodes.

OpenAI Chat, Gmail, Gmail Trigger +3