AutomationFlowsAI & RAG › Gmail Email Classifier with Gpt-4 Auto-generated Draft Replies

Gmail Email Classifier with Gpt-4 Auto-generated Draft Replies

BySupira Inc. @supira on n8n.io

This workflow automatically classifies incoming Gmail messages into categories such as High Priority, Inquiry, and Finance/Billing, and then generates professional draft replies using GPT-4. By combining Gmail integration with AI-powered text generation, the workflow helps…

Event trigger★★★★☆ complexityAI-powered15 nodesGmail TriggerGmailText ClassifierOpenAIOpenAI Chat
AI & RAG Trigger: Event Nodes: 15 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #8426 — 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": "yleYtr2zaJKjyMOK",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Gmail Email Classifier with GPT-4 Auto-Generated Draft Replies",
  "tags": [
    {
      "id": "eFlPj8ZRT4LrlBD1",
      "name": "Automation",
      "createdAt": "2025-09-09T16:15:06.029Z",
      "updatedAt": "2025-09-09T16:15:06.029Z"
    },
    {
      "id": "hjzY8e2beJ4ByFSh",
      "name": "Email Automation",
      "createdAt": "2025-09-09T16:15:20.964Z",
      "updatedAt": "2025-09-09T16:15:20.964Z"
    }
  ],
  "nodes": [
    {
      "id": "d388e4be-fe23-4f1b-919b-e9d19338750a",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -912,
        128
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyX",
              "unit": "minutes",
              "value": 15
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "fabeeec9-9900-44c9-9737-331d5eb1e927",
      "name": "Label: High Priority",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -336,
        -64
      ],
      "parameters": {
        "labelIds": [
          "YOUR_LABEL_ID_HIGH_PRIORITY"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2.1
    },
    {
      "id": "f6879258-e119-437f-8d07-9c9e9fb4977b",
      "name": "Save Draft: High Priority",
      "type": "n8n-nodes-base.gmail",
      "options": {
        "allowUnauthorizedCerts": false
      },
      "position": [
        240,
        -64
      ],
      "parameters": {
        "message": "{{ JSON.parse($json.message.content)['message'] || $json.message.content }}",
        "options": {
          "threadId": "={{ $('Gmail Trigger').item.json.threadId }}"
        },
        "subject": "{{ JSON.parse($json.message.content)['subject'] || `Re: ${$('Gmail Trigger').item.json.subject}` }}",
        "resource": "draft"
      },
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "56d6cee5-34e0-4011-acf0-a8fa6edeadc5",
      "name": "Label: Inquiry",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -336,
        128
      ],
      "parameters": {
        "labelIds": [
          "YOUR_LABEL_ID_INQUIRY"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2.1
    },
    {
      "id": "d544643d-faf5-4b22-b534-34d26950f0a2",
      "name": "Save Draft: Inquiry",
      "type": "n8n-nodes-base.gmail",
      "options": {
        "allowUnauthorizedCerts": false
      },
      "position": [
        240,
        128
      ],
      "parameters": {
        "message": "{{ JSON.parse($json.message.content)['message'] || $json.message.content }}",
        "options": {
          "threadId": "={{ $('Gmail Trigger').item.json.threadId }}"
        },
        "subject": "{{ JSON.parse($json.message.content)['subject'] || `Re: ${$('Gmail Trigger').item.json.subject}` }}",
        "resource": "draft"
      },
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "c07969cc-6dcd-44c0-9a1c-63d20dc61e4b",
      "name": "Label: Finance/Billing",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -336,
        320
      ],
      "parameters": {
        "labelIds": [
          "YOUR_LABEL_ID_FINANCE"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "typeVersion": 2.1
    },
    {
      "id": "712a6f08-8f71-4c13-8acb-b39b11d9f293",
      "name": "Save Draft: Finance/Billing",
      "type": "n8n-nodes-base.gmail",
      "options": {
        "allowUnauthorizedCerts": false
      },
      "position": [
        240,
        320
      ],
      "parameters": {
        "message": "{{ JSON.parse($json.message.content)['message'] || $json.message.content }}",
        "options": {
          "threadId": "={{ $('Gmail Trigger').item.json.threadId }}"
        },
        "subject": "{{ JSON.parse($json.message.content)['subject'] || `Re: ${$('Gmail Trigger').item.json.subject}` }}",
        "resource": "draft"
      },
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "4cb47a6d-3e08-4a2f-b18f-af56ab5fd1d7",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -112,
        512
      ],
      "parameters": {
        "content": "## Add your OpenAI API Key under \"Credentials\".\n"
      },
      "typeVersion": 1
    },
    {
      "id": "9654f73d-d725-4c6c-a41e-9711da06f5c8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -992,
        304
      ],
      "parameters": {
        "content": "## Connect your Gmail account under \"Credentials\"."
      },
      "typeVersion": 1
    },
    {
      "id": "92db5bbe-37bb-4edb-9637-5560b093b53e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -432,
        512
      ],
      "parameters": {
        "width": 288,
        "height": 192,
        "content": "## Replace YOUR_LABEL_ID_XXX\n with your Gmail label IDs (get them via Gmail \u2192 List Labels)."
      },
      "typeVersion": 1
    },
    {
      "id": "9347757e-ae21-44b3-9a66-9b158e9496ed",
      "name": "Gmail Category Classifier",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        -688,
        128
      ],
      "parameters": {
        "options": {},
        "inputText": "={{ $json.text }}",
        "categories": {
          "categories": [
            {
              "category": "High Priority",
              "description": "Urgent matters requiring immediate attention: deadline/requirements changes, incident reports, or escalations from executives/key clients."
            },
            {
              "category": "Promotions",
              "description": "Newsletters, sales, and event ads. No urgent action required."
            },
            {
              "category": "Inquiry",
              "description": "Questions/requests from customers or teammates. Aim to reply within 24\u201348h with a clear answer."
            },
            {
              "category": "Finance/Billing",
              "description": "Invoices/quotes/payments/receipts/due dates. Handle in order of due date."
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "b79ab780-f6a2-4d29-a6da-2f05f38ac271",
      "name": "Generate Draft: High Priority",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "options": {
        "continueOnFail": true
      },
      "position": [
        -112,
        -64
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are an Executive Assistant. Goal: Draft a fast, accurate reply for emails classified as \"High Priority\". Input email body: {{ $('Gmail Trigger').item.json.text }} Output a JSON object: {\"subject\":\"...\",\"message\":\"...\"}. Rules: (1) Start with a short summary and list clarifying questions (requirements/deadline/unknowns). (2) Provide an initial/provisional answer where possible. (3) Default subject format: \"Re: {{ $('Gmail Trigger').item.json.subject }} | Action & Clarifications\" (adjust if needed). Keep tone concise and professional."
            }
          ]
        },
        "jsonOutput": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "bc2956b4-4789-4747-854d-f3bc937cec23",
      "name": "Generate Draft: Inquiry",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "options": {
        "continueOnFail": true
      },
      "position": [
        -112,
        128
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a Customer Support agent. Goal: Draft a polite, complete reply to an \"Inquiry\" email. Input: {{ $('Gmail Trigger').item.json.text }} Output JSON: {\"subject\":\"...\",\"message\":\"...\"}. Structure: (1) Brief summary of the ask, (2) Direct answer/steps, (3) Next actions and expected timeline, (4) Optional links to FAQ/help. Add a simple signature. Default subject: \"Re: {{ $('Gmail Trigger').item.json.subject }} | Response to Your Question\"."
            }
          ]
        },
        "jsonOutput": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "955978cc-acde-4413-a11a-c197893d7ce8",
      "name": "Generate Draft: Finance/Billing",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "options": {
        "continueOnFail": true
      },
      "position": [
        -112,
        320
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a Finance Assistant. Goal: Draft a precise reply for \"Finance/Billing\" emails. Input: {{ $('Gmail Trigger').item.json.text }} Output JSON: {\"subject\":\"...\",\"message\":\"...\"}. Rules: (1) Confirm key fields in bullets (amount, due date, bank info, invoice/PO numbers), (2) Request any missing docs (quote/PO/delivery note/receipt), (3) State due date or next step clearly. Default subject: \"Re: {{ $('Gmail Trigger').item.json.subject }} | Billing Clarifications\"."
            }
          ]
        },
        "jsonOutput": true
      },
      "typeVersion": 1.8
    },
    {
      "id": "5ea6f7ea-2b75-4038-8f1e-4bb1d0cc473d",
      "name": "LLM Support Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -624,
        416
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "b8cb7ddb-65c0-4ca6-94b9-7d23cb801b2e",
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Gmail Category Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label: Inquiry": {
      "main": [
        [
          {
            "node": "Generate Draft: Inquiry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LLM Support Model": {
      "ai_languageModel": [
        [
          {
            "node": "Gmail Category Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Label: High Priority": {
      "main": [
        [
          {
            "node": "Generate Draft: High Priority",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Label: Finance/Billing": {
      "main": [
        [
          {
            "node": "Generate Draft: Finance/Billing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Draft: Inquiry": {
      "main": [
        [
          {
            "node": "Save Draft: Inquiry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Category Classifier": {
      "main": [
        [
          {
            "node": "Label: High Priority",
            "type": "main",
            "index": 0
          }
        ],
        [],
        [
          {
            "node": "Label: Inquiry",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Label: Finance/Billing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Draft: High Priority": {
      "main": [
        [
          {
            "node": "Save Draft: High Priority",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Draft: Finance/Billing": {
      "main": [
        [
          {
            "node": "Save Draft: Finance/Billing",
            "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

This workflow automatically classifies incoming Gmail messages into categories such as High Priority, Inquiry, and Finance/Billing, and then generates professional draft replies using GPT-4. By combining Gmail integration with AI-powered text generation, the workflow helps…

Source: https://n8n.io/workflows/8426/ — 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 n8n template demonstrates how to automate email classification, labeling, draft generation, and logging using Gmail, OpenAI, and Google Sheets. Use cases include customer support management, sale

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

This n8n template uses AI to automatically classify incoming Gmail messages into five categories and route them to the right people or departments. It can also reply automatically and send WhatsApp al

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

Detects new unread Gmail messages Extracts sender name for personalized replies Classifies the email into one of four categories Applies the correct Gmail label and either sends an auto-reply, creates

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

Email Automation AI-Powered Operations Internal Productivity Tools

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

This section automates Gmail message handling through AI-powered classification and response. Using the LangChain Text Classifier, incoming emails are analyzed and sorted into four categories — High P

Gmail Trigger, Text Classifier, OpenAI Chat +3