{"name": "Gmail AI Auto-Labeling & Inbox Triage", "nodes": [{"id": "gml2-0000-4a5b-8c9d-000000000001", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [160, -80], "parameters": {"color": 4, "content": "## Gmail AI Auto-Labeling & Inbox Triage\n\n**Two independent chains (not connected):**\n\n**Chain 1 - instant triage:** Gmail Trigger -> OpenAI classifies each new email (urgent/action/fyi/spam) -> Switch routes by category -> Gmail applies the matching label.\n\n**Chain 2 - daily digest:** Schedule Trigger (8 AM) -> Gmail fetches unread urgent/action emails -> OpenAI summarizes -> Gmail sends the digest to you.\n\n**Setup:**\n1. Create credentials: OpenAI and Gmail OAuth2; select them in every node.\n2. In Gmail, create 4 labels: Urgent, Action, FYI, Spam (Settings -> See all settings -> Labels).\n3. In each 'Gmail: Apply Label' node, set labelIds to the matching label.\n4. In 'Gmail: Send Digest', set the recipient to your own email.\n5. Activate.", "height": 380, "width": 480}}, {"id": "gml2-0001-4a5b-8c9d-111111111111", "name": "Gmail Trigger: New Email", "type": "n8n-nodes-base.gmailTrigger", "typeVersion": 1.2, "position": [240, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"pollTimes": {"item": [{"mode": "everyMinute"}]}, "filters": {}}}, {"id": "gml2-0002-4a5b-8c9d-222222222222", "name": "OpenAI: Classify Email", "type": "n8n-nodes-base.openAi", "typeVersion": 1, "position": [480, 300], "credentials": {"openAiApi": {"id": "", "name": "OpenAI API"}}, "parameters": {"resource": "text", "operation": "message", "model": "gpt-4o-mini", "messages": {"message": [{"role": "user", "content": "=Classify this email into exactly one category.\n\nCategories:\n- urgent: time-sensitive, needs action today\n- action: needs a reply or task, not time-sensitive\n- fyi: informational only\n- spam: junk, promotions, or phishing\n\nSubject: {{ $json.subject }}\nSnippet: {{ $json.snippet }}\n\nReply with exactly one word and nothing else: urgent, action, fyi, or spam."}]}, "options": {}}}, {"id": "gml2-0003-4a5b-8c9d-333333333333", "name": "Switch: Route by Category", "type": "n8n-nodes-base.switch", "typeVersion": 3.2, "position": [720, 300], "parameters": {"rules": {"values": [{"conditions": {"options": {"caseSensitive": true, "leftValue": "", "typeValidation": "strict"}, "conditions": [{"id": "s-urgent", "leftValue": "={{ $json.message.content.trim().toLowerCase() }}", "rightValue": "urgent", "operator": {"type": "string", "operation": "equals", "name": "filter.operator.string.equals"}}], "combinator": "and"}, "renameOutput": true, "outputKey": "urgent"}, {"conditions": {"options": {"caseSensitive": true, "leftValue": "", "typeValidation": "strict"}, "conditions": [{"id": "s-action", "leftValue": "={{ $json.message.content.trim().toLowerCase() }}", "rightValue": "action", "operator": {"type": "string", "operation": "equals", "name": "filter.operator.string.equals"}}], "combinator": "and"}, "renameOutput": true, "outputKey": "action"}, {"conditions": {"options": {"caseSensitive": true, "leftValue": "", "typeValidation": "strict"}, "conditions": [{"id": "s-fyi", "leftValue": "={{ $json.message.content.trim().toLowerCase() }}", "rightValue": "fyi", "operator": {"type": "string", "operation": "equals", "name": "filter.operator.string.equals"}}], "combinator": "and"}, "renameOutput": true, "outputKey": "fyi"}, {"conditions": {"options": {"caseSensitive": true, "leftValue": "", "typeValidation": "strict"}, "conditions": [{"id": "s-spam", "leftValue": "={{ $json.message.content.trim().toLowerCase() }}", "rightValue": "spam", "operator": {"type": "string", "operation": "equals", "name": "filter.operator.string.equals"}}], "combinator": "and"}, "renameOutput": true, "outputKey": "spam"}]}, "options": {"fallbackOutput": "extra", "renameFallbackOutput": true, "fallbackOutputName": "other"}}}, {"id": "gml2-0004-4a5b-8c9d-000000000000", "name": "Gmail: Apply Label - Urgent", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [960, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "addLabels", "messageId": "={{ $('Gmail Trigger: New Email').item.json.id }}", "labelIds": ["Label_Urgent"], "options": {}}}, {"id": "gml2-0004-4a5b-8c9d-000000000001", "name": "Gmail: Apply Label - Action", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [1200, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "addLabels", "messageId": "={{ $('Gmail Trigger: New Email').item.json.id }}", "labelIds": ["Label_Action"], "options": {}}}, {"id": "gml2-0004-4a5b-8c9d-000000000002", "name": "Gmail: Apply Label - FYI", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [1440, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "addLabels", "messageId": "={{ $('Gmail Trigger: New Email').item.json.id }}", "labelIds": ["Label_FYI"], "options": {}}}, {"id": "gml2-0004-4a5b-8c9d-000000000003", "name": "Gmail: Apply Label - Spam", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [1680, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "addLabels", "messageId": "={{ $('Gmail Trigger: New Email').item.json.id }}", "labelIds": ["Label_Spam"], "options": {}}}, {"id": "gml2-0008-4a5b-8c9d-888888888888", "name": "Schedule Trigger: Daily Digest", "type": "n8n-nodes-base.scheduleTrigger", "typeVersion": 1.2, "position": [240, 600], "parameters": {"rule": {"interval": [{"field": "cron", "cronExpression": "0 8 * * *"}]}}}, {"id": "gml2-0009-4a5b-8c9d-999999999999", "name": "Gmail: Fetch Labeled Unread", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [480, 600], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "getAll", "filters": {"q": "is:unread (label:urgent OR label:action) newer_than:1d"}, "options": {"limit": 50}}}, {"id": "gml2-0010-4a5b-8c9d-aaaaaaaaaaaaaaaa", "name": "OpenAI: Summarize Digest", "type": "n8n-nodes-base.openAi", "typeVersion": 1, "position": [720, 600], "credentials": {"openAiApi": {"id": "", "name": "OpenAI API"}}, "parameters": {"resource": "text", "operation": "message", "model": "gpt-4o-mini", "messages": {"message": [{"role": "user", "content": "=Summarize these emails into a short morning digest. One line per email: sender, subject, and why it matters. Group urgent ones first.\n\n{{ JSON.stringify($json, null, 2) }}"}]}, "options": {}}}, {"id": "gml2-0011-4a5b-8c9d-bbbbbbbbbbbb", "name": "Gmail: Send Digest", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [960, 600], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "send", "subject": "=Daily inbox digest - {{ $now.format('yyyy-MM-dd') }}", "email": "you@example.com", "message": "=Good morning,\n\nHere is your inbox digest:\n\n{{ $json.message.content }}", "options": {}}}], "connections": {"Gmail Trigger: New Email": {"main": [[{"node": "OpenAI: Classify Email", "type": "main", "index": 0}]]}, "OpenAI: Classify Email": {"main": [[{"node": "Switch: Route by Category", "type": "main", "index": 0}]]}, "Switch: Route by Category": {"main": [[{"node": "Gmail: Apply Label - Urgent", "type": "main", "index": 0}], [{"node": "Gmail: Apply Label - Action", "type": "main", "index": 0}], [{"node": "Gmail: Apply Label - FYI", "type": "main", "index": 0}], [{"node": "Gmail: Apply Label - Spam", "type": "main", "index": 0}]]}, "Schedule Trigger: Daily Digest": {"main": [[{"node": "Gmail: Fetch Labeled Unread", "type": "main", "index": 0}]]}, "Gmail: Fetch Labeled Unread": {"main": [[{"node": "OpenAI: Summarize Digest", "type": "main", "index": 0}]]}, "OpenAI: Summarize Digest": {"main": [[{"node": "Gmail: Send Digest", "type": "main", "index": 0}]]}}, "active": false, "settings": {"executionOrder": "v1"}, "versionId": "cortexflow-gmail-ai-auto-labeling-triage-v1", "meta": {"templateCredsSetupCompleted": false, "instanceId": ""}, "pinData": {}, "tags": [{"name": "cortexflow-template"}]}