基于 Gmail 和 GPT 的 AI 驱动邮件分类与自动回复系统
高级
这是一个Ticket Management、Multimodal AI领域的自动化工作流,包含 24 个节点。主要使用 If、Set、Gmail、Merge、GmailTrigger 等节点。 使用 GPT-4.1-mini 分类和 Gmail 自动回复实现邮件分拣自动化
前置要求
- •Google 账号和 Gmail API 凭证
- •Google Sheets API 凭证
- •OpenAI API Key
使用的节点 (24 个)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "Nj73lhp3xoOM5vJR",
"meta": {
"instanceId": "465f4422bb16aa276130544b590fd34d3a02b10a5aa0e96f6c6adc306e3e8296",
"templateCredsSetupCompleted": true
},
"name": "基于 Gmail 和 GPT 的 AI 驱动邮件分类与自动回复系统",
"tags": [],
"nodes": [
{
"id": "1c25bce1-dce3-408f-8c17-f4e2cde60f26",
"name": "Gmail 触发器",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
0,
80
],
"parameters": {
"simple": false,
"filters": {
"readStatus": "unread"
},
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 1.2
},
{
"id": "e39fd2c4-76b2-4cb9-816e-b0e146b81be3",
"name": "条件判断",
"type": "n8n-nodes-base.if",
"position": [
600,
100
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "2d7cba78-1e46-4563-9683-2151f4bc3cc6",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
},
"leftValue": "={{ $json.output.sender_name }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "1f9d175e-dd19-4a5e-b4cf-68c67769514e",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
220,
240
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "x61T2jyBPZhaqKVW",
"name": "n8n free OpenAI API credits"
}
},
"typeVersion": 1.2
},
{
"id": "7547e456-d72e-4bd7-a483-e600026132a1",
"name": "找到姓名",
"type": "n8n-nodes-base.set",
"position": [
820,
0
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "0064bc2e-17b5-4d55-945e-ad61c4a7e796",
"name": "intro_line",
"type": "string",
"value": "=Dear {{ $json.output.sender_name }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "f5335b2d-2732-47fc-a916-17bd9d40e0da",
"name": "未找到姓名",
"type": "n8n-nodes-base.set",
"position": [
820,
200
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "0064bc2e-17b5-4d55-945e-ad61c4a7e796",
"name": "intro_line",
"type": "string",
"value": "=Hey,"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "53f97b56-7bc6-4f25-b3c7-761fb38d7174",
"name": "OpenAI 聊天模型1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
200,
960
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "jJNoHsAQMgxbuAcB",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "2cc7a078-016e-4205-897d-a6c20f23dd52",
"name": "标签 - 机构线索",
"type": "n8n-nodes-base.gmail",
"position": [
560,
420
],
"webhookId": "b9cae76f-27ae-41e6-a806-61de5db8b020",
"parameters": {
"labelIds": [
"Label_2779457653887615300"
],
"messageId": "={{ $json.message_id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 2.1
},
{
"id": "af773077-758f-4f64-94b2-658784b8689d",
"name": "标签 - 课程请求",
"type": "n8n-nodes-base.gmail",
"position": [
560,
620
],
"webhookId": "b9cae76f-27ae-41e6-a806-61de5db8b020",
"parameters": {
"labelIds": [
"Label_6090976944524934821"
],
"messageId": "={{ $json.message_id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 2.1
},
{
"id": "a93709f4-15a0-4333-b9e1-aff10ff6c693",
"name": "标签 - 付费合作",
"type": "n8n-nodes-base.gmail",
"position": [
560,
820
],
"webhookId": "b9cae76f-27ae-41e6-a806-61de5db8b020",
"parameters": {
"labelIds": [
"Label_2508736995105587525"
],
"messageId": "={{ $json.message_id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 2.1
},
{
"id": "7994e586-a28c-47d6-902f-9389516d13f7",
"name": "标签 - 其他",
"type": "n8n-nodes-base.gmail",
"position": [
560,
1020
],
"webhookId": "b9cae76f-27ae-41e6-a806-61de5db8b020",
"parameters": {
"labelIds": [
"Label_5123095855127638673"
],
"messageId": "={{ $json.message_id }}",
"operation": "addLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 2.1
},
{
"id": "f7c8cc18-f017-4a5d-92e9-c80d16a1269a",
"name": "向模型发送消息",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
780,
420
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini",
"cachedResultName": "GPT-4.1-MINI"
},
"options": {},
"messages": {
"values": [
{
"role": "system",
"content": "You are an intelligent and useful personal assistant that replies to my emails"
},
{
"content": "=Here's the email to reply to:\n\nIntro line for the sender:{{ $('Single Intro Line').item.json.intro_line }}\nEmail Body: {{ $('Gmail Trigger').item.json.text }}\nEmail Subject:{{ $('Gmail Trigger').item.json.subject }}"
},
{
"content": "=Please format the data in this format:\n\n{\n\n\"subject\": \"The subject line fo the email you drafted\"\n\"body\": \"The body of the email you drafted\"\n\n}"
}
]
},
"jsonOutput": true
},
"credentials": {
"openAiApi": {
"id": "jJNoHsAQMgxbuAcB",
"name": "OpenAi account"
}
},
"typeVersion": 1.8
},
{
"id": "5c4ae3ba-5ab9-46c3-aa20-b43d8c62a1a3",
"name": "创建草稿",
"type": "n8n-nodes-base.gmail",
"position": [
1140,
420
],
"webhookId": "0c43d685-5746-44ff-ae3a-6b5b356801f1",
"parameters": {
"message": "={{ $json.message.content.body }}",
"options": {
"threadId": "={{ $('Label - Agency Lead').item.json.threadId }}"
},
"subject": "={{ $json.message.content.subject }}",
"resource": "draft"
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 2.1
},
{
"id": "51f46e0e-4280-414d-9f1f-545027c6965a",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
180,
0
],
"parameters": {
"width": 300,
"height": 360,
"content": "## 姓名提取器"
},
"typeVersion": 1
},
{
"id": "ee1210c5-62c0-41f5-be0a-0ca4b90879b6",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
560,
-40
],
"parameters": {
"color": 5,
"width": 600,
"height": 400,
"content": "## 个性化开场白"
},
"typeVersion": 1
},
{
"id": "3097cff4-606a-46ab-9982-a79ff30ed097",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-80,
540
],
"parameters": {
"color": 4,
"width": 560,
"height": 600,
"content": "## 情感分析"
},
"typeVersion": 1
},
{
"id": "956a90c8-0752-41a3-8496-bf3c5e9eb94f",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
520,
380
],
"parameters": {
"color": 6,
"width": 860,
"height": 800,
"content": "## 个性化开场白"
},
"typeVersion": 1
},
{
"id": "24ce2fe3-e674-4d47-b7b3-6dc8eb94a328",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1120,
-100
],
"parameters": {
"color": 3,
"width": 960,
"height": 1240,
"content": "# 概述"
},
"typeVersion": 1
},
{
"id": "88e31730-9014-4076-bc2a-71d1dab5ef78",
"name": "姓名提取器",
"type": "@n8n/n8n-nodes-langchain.informationExtractor",
"position": [
220,
80
],
"parameters": {
"text": "={{ $json.text }}",
"options": {
"systemPromptTemplate": "=You are an expert extraction algorithm.\nOnly extract relevant information from the text.\nIf you do not know the value of an attribute asked to extract, you may omit the attribute's value."
},
"attributes": {
"attributes": [
{
"name": "sender_name",
"required": true,
"description": "=This is the sender name, which corresponds to the signature of the sender at the end of the body of the email. If the name is not available, return an empty string."
}
]
}
},
"typeVersion": 1.2
},
{
"id": "e97c25b3-84f0-4602-86cc-45652f9a6bf8",
"name": "单行开场白",
"type": "n8n-nodes-base.merge",
"position": [
1040,
100
],
"parameters": {
"mode": "combine",
"options": {},
"joinMode": "keepNonMatches",
"fieldsToMatchString": "=intro_line"
},
"typeVersion": 3.2
},
{
"id": "0568b7a5-017a-4db1-94f1-bf80057db779",
"name": "在 LLM 前减少内容",
"type": "n8n-nodes-base.set",
"position": [
-40,
720
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "a5357d59-3a7a-4197-b005-a8fa4acea9c0",
"name": "intro_line",
"type": "string",
"value": "={{ $json.intro_line }}"
},
{
"id": "17c5b46b-77e6-43ab-a314-6a36a21651f8",
"name": "email_body",
"type": "string",
"value": "={{ $('Gmail Trigger').item.json.text }}"
},
{
"id": "e534b113-0a05-4312-b577-b1918f03b361",
"name": "message_id",
"type": "string",
"value": "={{ $('Gmail Trigger').item.json.id }}"
},
{
"id": "21ab6542-a5b6-4ca0-9605-4f1c9b27e70d",
"name": "thread_id",
"type": "string",
"value": "={{ $('Gmail Trigger').item.json.threadId }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "9434fc19-bbb8-4778-8e9b-49b7777cac77",
"name": "AI 分类与情感分析",
"type": "@n8n/n8n-nodes-langchain.textClassifier",
"position": [
200,
720
],
"parameters": {
"options": {},
"inputText": "={{ $json.email_body }}",
"categories": {
"categories": [
{
"category": "Agency Lead",
"description": "This includes people/companies interested in inquiries regarding AI solutions, may it be asking info on what they can do, or me building a solution for them."
},
{
"category": "Course Request",
"description": "This includes inquiries from people regarding which courses they should choose in order to understand/study AI or AI Agents "
},
{
"category": "Paid Collaborations",
"description": "Inquiries regarding sponsorship of books or tools on my channels. There are also situations in which they don't specifically say that they will pay, but they ask me to share their material with my audience"
},
{
"category": "Miscellaneous",
"description": "All the remaining messages"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "680a89f0-148f-4b91-a63f-a428744ba177",
"name": "标准回答",
"type": "n8n-nodes-base.gmail",
"position": [
840,
620
],
"webhookId": "fd82eb8a-6d1c-4509-ab21-1674cb6328d2",
"parameters": {
"message": "={{ $('AI-Classification & Sentiment Analysis').item.json.intro_line }},\n\nThanks for reaching out.\n\nThis email goes out as soon as I receive a request of a course recommendation.\n\nThis is my phone number: XXXX\n\nPlease reach out to me there!\n\nThanks,\nGiovanni",
"options": {},
"emailType": "text",
"messageId": "={{ $json.id }}",
"operation": "reply"
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 2.1
},
{
"id": "bcd48315-4957-4cd1-81e2-97ea4ea1431e",
"name": "标准回答 2",
"type": "n8n-nodes-base.gmail",
"position": [
840,
820
],
"webhookId": "fd82eb8a-6d1c-4509-ab21-1674cb6328d2",
"parameters": {
"message": "={{ $('AI-Classification & Sentiment Analysis').item.json.intro_line }},\n\nThanks for reaching out.\n\nThis email goes out as soon as I receive a request of a paid collab.\n\nThis is my phone number: XXXX\n\nPlease reach out to me there!\n\nThanks,\nGiovanni",
"options": {},
"emailType": "text",
"messageId": "={{ $json.id }}",
"operation": "reply"
},
"credentials": {
"gmailOAuth2": {
"id": "SWlhbg6fDyvBn2oz",
"name": "giobeggiato@gmail.com"
}
},
"typeVersion": 2.1
},
{
"id": "39a258ef-64a3-45df-b048-0de048a4825c",
"name": "更新数据库",
"type": "n8n-nodes-base.googleSheets",
"position": [
1140,
820
],
"parameters": {
"columns": {
"value": {
"Name": "={{ $('Single Intro Line').item.json.intro_line.replace('Dear ', '') }}",
"email": "={{ $('Gmail Trigger').item.json.from.value[0].address }}",
"subject": "={{ $('Gmail Trigger').item.json.subject }}"
},
"schema": [
{
"id": "Name",
"type": "string",
"display": true,
"required": false,
"displayName": "Name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "email",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "email",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "subject",
"type": "string",
"display": true,
"required": false,
"displayName": "subject",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"email"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "appendOrUpdate",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1mW0vLLwJXdWBEe5_JxT9HfK1U8ECygmu-zNnfOf93Xo/edit#gid=0",
"cachedResultName": "Sheet1"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1mW0vLLwJXdWBEe5_JxT9HfK1U8ECygmu-zNnfOf93Xo",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1mW0vLLwJXdWBEe5_JxT9HfK1U8ECygmu-zNnfOf93Xo/edit?usp=drivesdk",
"cachedResultName": "Paid Collaborations"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "Urd6OjD5xri8sIO1",
"name": "Working_Sheets_bli"
}
},
"typeVersion": 4.6
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "030afcdb-4da5-4947-aafe-042dae86a937",
"connections": {
"If": {
"main": [
[
{
"node": "Name Found",
"type": "main",
"index": 0
}
],
[
{
"node": "Name Not Found",
"type": "main",
"index": 0
}
]
]
},
"Name Found": {
"main": [
[
{
"node": "Single Intro Line",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Name Extractor",
"type": "main",
"index": 0
}
]
]
},
"Name Extractor": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"Name Not Found": {
"main": [
[
{
"node": "Single Intro Line",
"type": "main",
"index": 1
}
]
]
},
"Message a model": {
"main": [
[
{
"node": "Create a draft",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Name Extractor",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Single Intro Line": {
"main": [
[
{
"node": "Reducing content before LLM",
"type": "main",
"index": 0
}
]
]
},
"Standard Answer 2": {
"main": [
[
{
"node": "Update DB",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model1": {
"ai_languageModel": [
[
{
"node": "AI-Classification & Sentiment Analysis",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Label - Agency Lead": {
"main": [
[
{
"node": "Message a model",
"type": "main",
"index": 0
}
]
]
},
"Label - Course Request": {
"main": [
[
{
"node": "Standard Answer",
"type": "main",
"index": 0
}
]
]
},
"Label - Paid Collaborations": {
"main": [
[
{
"node": "Standard Answer 2",
"type": "main",
"index": 0
}
]
]
},
"Reducing content before LLM": {
"main": [
[
{
"node": "AI-Classification & Sentiment Analysis",
"type": "main",
"index": 0
}
]
]
},
"AI-Classification & Sentiment Analysis": {
"main": [
[
{
"node": "Label - Agency Lead",
"type": "main",
"index": 0
}
],
[
{
"node": "Label - Course Request",
"type": "main",
"index": 0
}
],
[
{
"node": "Label - Paid Collaborations",
"type": "main",
"index": 0
}
],
[
{
"node": "Label - Miscellaneous",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Ticket Management、Multimodal AI等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
基于AI的MIS代理
基于AI的管理信息系统代理
If
Set
Code
+29
129 节点Kumar Shivam
Support
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
Other
AI驱动的邮件分诊与自动回复系统,集成OpenAI代理和Gmail
AI驱动的邮件分诊与自动回复系统,集成OpenAI代理和Gmail
If
Set
Gmail
+20
68 节点Abdullahi Ahmed
Content Creation
GPT-4o与错误处理的自动化简历筛选 - Google表格与云端硬盘流程
GPT-4o与错误处理的自动化简历筛选 - Google表格与云端硬盘流程
If
Set
Gmail
+12
34 节点David Olusola
Content Creation
带AI的邮件自动回复器(含人工验证)
使用GPT和人工验证循环自动化Gmail回复
If
Set
Code
+5
20 节点Nick Canfield
Ticket Management
自适应邮件自动回复器(GPT-4、RAG和人工反馈循环)
自适应邮件自动回复器(GPT-4、RAG和人工反馈循环)
If
Set
Gmail
+15
38 节点LeeWei
Content Creation
工作流信息
难度等级
高级
节点数量24
分类2
节点类型11
作者
Giovanni Beggiato
@giovannibeggiatoHi 👋 I’m Gio. I make money with AI automation & teach others how they can too. If you have any questions about my templates or n8n builds, drop them in the comments and I’ll be happy to help.
外部链接
在 n8n.io 上查看 →
分享此工作流