Marquage automatique des e-mails entrants de Gmail
Ceci est unTicket Management, AI Summarizationworkflow d'automatisation du domainecontenant 17 nœuds.Utilise principalement des nœuds comme Gmail, Filter, Switch, GmailTrigger, Agent. Classer et étiqueter automatiquement les e-mails Gmail avec GPT-4o mini
- •Compte Google et informations d'identification Gmail API
- •Clé API OpenAI
Catégorie
{
"id": "ggkJA0uoozwG7xjI",
"meta": {
"instanceId": "0a82a9d5784b67ad963ceff89283b2e40cb771be10fe58ba2682f3598a37c6e1",
"templateCredsSetupCompleted": true
},
"name": "Auto-label incoming Gmail emails using AI",
"tags": [
{
"id": "Ii0eAkipojnzTClF",
"name": "arlindeveloper",
"createdAt": "2025-06-27T00:20:16.715Z",
"updatedAt": "2025-06-27T00:20:16.715Z"
}
],
"nodes": [
{
"id": "43213c04-af84-46b3-95a1-e1ed1112f988",
"name": "Déclencheur Gmail",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
-260,
1640
],
"parameters": {
"simple": false,
"filters": {},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 1.2
},
{
"id": "65924fac-5776-4e4f-928a-d1180e730a9c",
"name": "Modèle de chat OpenAI2",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
300,
1880
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini",
"cachedResultName": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "wAP7QjMnHDyoGfIB",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "887dac9a-7bae-4797-8967-1114660c194a",
"name": "Structured Output Parser1",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
560,
1880
],
"parameters": {
"jsonSchemaExample": "{\n \"email_label\": \"business\"\n}"
},
"typeVersion": 1.2
},
{
"id": "fa913085-1c4f-4d61-938c-9bbf24fe9e69",
"name": "Note adhésive3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-360,
1380
],
"parameters": {
"color": 7,
"width": 560,
"height": 700,
"content": "## 1. Gmail Trigger + Label Checker\n[Read more about Gmail Trigger node Editing](https://docs.n8n.io/integrations/builtin/trigger-nodes/n8n-nodes-base.gmailtrigger/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.gmailTrigger)\n[Read more about Filter node editing](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.filter/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.filter)\n\n📬 Incoming email check\nThis section triggers when a new email is received in Gmail.\nIt uses a filter to ignore any emails that already have labels, so only unlabeled messages are processed.\nYou can adjust the frequency of the trigger (e.g., every minute, hours or Custom using Cron ⏱️) in the Gmail node."
},
"typeVersion": 1
},
{
"id": "a9c899ef-a4f5-4947-9d9b-5d579ae58827",
"name": "Note adhésive11",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1020,
1380
],
"parameters": {
"width": 620,
"height": 1100,
"content": "## Sort Gmail messages by category with AI \n\n## 👥 Who's it for \nThis workflow is perfect for individuals or teams who receive a high volume of emails 📥 and want to automatically organize them into Gmail labels 🏷️ using AI. No coding required!\n\n## 🤖 What it does \nIt automatically processes new Gmail emails, skips those that already have labels, sends the content to an AI Agent powered by GPT-4o mini 🧠, and applies a relevant label based on the content. All labels must exist in Gmail beforehand.\n\n## ⚙️ How it works \n1. **📬 Gmail Trigger** – Activates on new email received. \n2. **🚫 Filter** – Skips emails that already have a label. \n3. **🧠 AI Agent (GPT-4o mini)** – Analyzes the message and decides which label fits best. \n4. **🧾 Structured Output Parser** – Formats the AI output into a clean JSON. \n5. **🔀 Switch Node** – Routes each email to the correct label path based on the AI result. \n6. **🏷️ Gmail Nodes** – Assign the Gmail label to the original email.\n\n## 📋 Requirements \n- Gmail account connected to n8n \n- Pre-created labels in Gmail matching the AI categories \n- OpenAI credentials with GPT-4o mini access \n- n8n's AI Agent & Structured Output Parser nodes \n\n## 🛠️ How to set up \n1. Open the workflow and adjust the **trigger interval** (e.g., every minute, hours or Custom using Cron ⏱️) \n2. Check that the **Filter** skips emails with existing labels \n3. Define your categories in the **AI Agent prompt** and make sure they match the Gmail labels \n4. Configure the **Switch Node** conditions for each category \n5. Ensure each **Gmail Label Node** applies the correct label \n6. Save and activate the workflow ✅\n\n## 🎨 How to customize the workflow \n- Add or remove categories in the AI prompt & Switch Node \n- Fine-tune prompt instructions to match your specific use case \n"
},
"typeVersion": 1
},
{
"id": "0415122e-6746-408c-a4eb-5d128c80a921",
"name": "Note adhésive12",
"type": "n8n-nodes-base.stickyNote",
"position": [
220,
1380
],
"parameters": {
"color": 7,
"width": 560,
"height": 700,
"content": "## 2. AI Agent (GPT-4o mini + Output Parser)\n[Read more about the AI Agent node editing](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=%40n8n%2Fn8n-nodes-langchain.agent)\n[Read more about the Structured Output Parser node editing](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.outputparserstructured/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=%40n8n%2Fn8n-nodes-langchain.outputParserStructured)\n\n🧠 AI-powered categorization\nThe email content is sent to an AI Agent using GPT-4o mini to determine the appropriate label.\nMake sure the prompt includes your predefined categories, and that these labels already exist in Gmail.\nThe Structured Output Parser ensures the AI response is formatted like this:\n{ \"email_label\": \"Your Category Name\" }"
},
"typeVersion": 1
},
{
"id": "446e3625-8388-44f6-b04e-2d2483f1d4d5",
"name": "Note adhésive13",
"type": "n8n-nodes-base.stickyNote",
"position": [
800,
1380
],
"parameters": {
"color": 7,
"width": 760,
"height": 1300,
"content": "## 3. Apply labels based on AI output\n[Read more about Switch node editing](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.switch/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.switch)\n[Read more about Gmail node editing](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.gmail/message-operations/#add-label-to-a-message)\n\n🏷️ Apply labels based on AI output\nThe Switch node uses email_label from the AI response to route each email to the correct label path.\nEach branch corresponds to one category.\nThen, each Gmail node applies the label that matches the category.\n⚠️ Make sure each route and label name matches exactly."
},
"typeVersion": 1
},
{
"id": "4b4a928d-5305-40e5-a040-8a2e8787cf30",
"name": "Give a Label Agent IA",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
340,
1640
],
"parameters": {
"text": "=Topic: {{ $json.subject }}\nDescription: {{ $json.text }}\nSender: {{ $json.from.text }}",
"options": {
"systemMessage": "=**Your Role**\n\nYou are an intelligent email assistant responsible for sorting incoming messages. Your task is to analyze the content, subject, and sender of each email and assign it to the appropriate category.\n\n**Categories**\n\nCategories for sorting:\n\n-Work: Emails related to jobs, coworkers, meetings, projects, or professional tasks.\n\n-Personal: Messages from friends, family, or general personal life content.\n\n-Finance: Bank emails, invoices, receipts, bills, or payment confirmations.\n\n-Shopping: Order confirmations, promotions, receipts, or product updates from stores.\n\n-Travel: Booking confirmations, tickets, hotel or car rental details, itineraries.\n\n-Newsletters: Recurring marketing or informational emails from subscriptions or blogs.\n\n-Others: Relevant emails that don’t clearly fit into any of the categories above.\n\n**Instructions**\n\n-For each email:\n\n-Analyze the content, subject, and sender\n\n-Assign it to the appropriate category\n\n-Add a label with the category\n\n-If you are unsure, do not label the message\n\n**Response Format**\n\nAlways return the result in JSON format:\n\n{\n \"email_label\": \"Shopping\"\n}\n\nIMPORTANT – the response must use the exact label format as listed (capitalized with spaces).\n"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.8
},
{
"id": "5301b42e-ba3c-4f3c-8f84-e4f9ee4ca724",
"name": "Label Checker Filtrer",
"type": "n8n-nodes-base.filter",
"position": [
-40,
1640
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "6c287523-4ae2-43c4-8f9a-faf756f01855",
"operator": {
"type": "string",
"operation": "notContains"
},
"leftValue": "={{ $json.labelIds[0] }}",
"rightValue": "Label"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "3ccb8cd6-a329-4507-8158-cbc81b2d31da",
"name": "Commutateur",
"type": "n8n-nodes-base.switch",
"position": [
840,
1940
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Work",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "10893f03-231e-4dba-bfdf-69530f908b4d",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.email_label }}",
"rightValue": "Work"
}
]
},
"renameOutput": true
},
{
"outputKey": "Personal",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "23e430c2-ac8b-4fb5-bb5a-1fafb9e41b09",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.email_label }}",
"rightValue": "Personal"
}
]
},
"renameOutput": true
},
{
"outputKey": "Finance",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "53698e8e-f038-405d-a1d3-274dba7fb2a2",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.email_label }}",
"rightValue": "Finance"
}
]
},
"renameOutput": true
},
{
"outputKey": "Shopping",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "b3b7ffc6-d046-402f-8c9d-2e19d00b49a7",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.email_label }}",
"rightValue": "Shopping"
}
]
},
"renameOutput": true
},
{
"outputKey": "Travel",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "4e0a670b-4017-4d83-b01a-78a79c55daf2",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.email_label }}",
"rightValue": "Travel"
}
]
},
"renameOutput": true
},
{
"outputKey": "Newsletters",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "f0079792-cf4b-4c3e-8aed-48e2dddb4e05",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.email_label }}",
"rightValue": "Newsletters"
}
]
},
"renameOutput": true
},
{
"outputKey": "Others",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "a0c39fdd-3312-4a34-8cd4-41a1a10f9149",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.email_label }}",
"rightValue": "Others"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "70f0255c-de96-44a0-bcd0-748c9f6e4fe4",
"name": "Work",
"type": "n8n-nodes-base.gmail",
"position": [
1320,
1560
],
"webhookId": "265d6794-4bc1-44e5-b7b0-3a327c860235",
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "525f3f9f-9bc7-40f1-b6a5-8c3edd75025f",
"name": "Personal",
"type": "n8n-nodes-base.gmail",
"position": [
1320,
1720
],
"webhookId": "d63928b3-89bb-4549-b241-8a5462db0116",
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "84059ca7-f0cb-4582-bfb7-75f2678c1dae",
"name": "Finance",
"type": "n8n-nodes-base.gmail",
"position": [
1320,
1880
],
"webhookId": "e35bc26e-3b63-471a-8c82-909ccc4aac6c",
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "eb7f8180-c834-4f2a-b102-7e5bbacaca3b",
"name": "Shopping",
"type": "n8n-nodes-base.gmail",
"position": [
1160,
2020
],
"webhookId": "29f83d35-3ad1-4e5b-9359-8b9b2e83ed80",
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "12ba969b-d0aa-475c-ab5e-e4151f8df96e",
"name": "Travel",
"type": "n8n-nodes-base.gmail",
"position": [
1320,
2140
],
"webhookId": "4513f916-1685-4733-8fa6-6373a90abc5e",
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "41bebc40-ba6a-448e-8e28-d74b9ed73de6",
"name": "Newsletters",
"type": "n8n-nodes-base.gmail",
"position": [
1320,
2320
],
"webhookId": "523b3148-4ff3-4bf5-be9b-31a4b7739b3c",
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "9b3690d5-419c-4b4f-9e86-8720a94818d9",
"name": "Others",
"type": "n8n-nodes-base.gmail",
"position": [
1320,
2500
],
"webhookId": "b20366d0-4de9-4c99-a577-a14bfff50faf",
"parameters": {
"messageId": "={{ $('Gmail Trigger').item.json.id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "pVkuuYNT0KTxFcw0",
"name": "Gmail account"
}
},
"typeVersion": 2.1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "551de827-cf86-472f-935e-99539be78588",
"connections": {
"Switch": {
"main": [
[
{
"node": "70f0255c-de96-44a0-bcd0-748c9f6e4fe4",
"type": "main",
"index": 0
}
],
[
{
"node": "525f3f9f-9bc7-40f1-b6a5-8c3edd75025f",
"type": "main",
"index": 0
}
],
[
{
"node": "84059ca7-f0cb-4582-bfb7-75f2678c1dae",
"type": "main",
"index": 0
}
],
[
{
"node": "eb7f8180-c834-4f2a-b102-7e5bbacaca3b",
"type": "main",
"index": 0
}
],
[
{
"node": "12ba969b-d0aa-475c-ab5e-e4151f8df96e",
"type": "main",
"index": 0
}
],
[
{
"node": "41bebc40-ba6a-448e-8e28-d74b9ed73de6",
"type": "main",
"index": 0
}
],
[
{
"node": "9b3690d5-419c-4b4f-9e86-8720a94818d9",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Label Checker Filter",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model2": {
"ai_languageModel": [
[
{
"node": "Give a Label AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Label Checker Filter": {
"main": [
[
{
"node": "Give a Label AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Give a Label AI Agent": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
},
"887dac9a-7bae-4797-8967-1114660c194a": {
"ai_outputParser": [
[
{
"node": "Give a Label AI Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
}
}
}Comment utiliser ce workflow ?
Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.
Dans quelles scénarios ce workflow est-il adapté ?
Avancé - Gestion des tickets, Résumé IA
Est-ce payant ?
Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.
Workflows recommandés
Arlin Perez
@arlindeveloper👋 Hi! I'm Arlin - a QA Engineer with 2 years of experience and a background in Dart & Flutter for mobile app development. ⚙️ I'm passionate about automation and love building efficient workflows using n8n. 📬 Reach out on LinkedIn for any help with custom workflows
Partager ce workflow