使用 Gmail 和 GPT-4 自动化邮件分类与回复生成
中级
这是一个Ticket Management, Multimodal AI领域的自动化工作流,包含 15 个节点。主要使用 If, Gmail, OpenAi, Webhook, GoogleSheets 等节点。 使用 Gmail 和 GPT-4 自动化邮件分类与回复生成
前置要求
- •Google 账号和 Gmail API 凭证
- •OpenAI API Key
- •HTTP Webhook 端点(n8n 会自动生成)
- •Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "e7ccf4281d5afb175c79c02db95b45f15d5b53862cb6bc357c5e5bc26567f35c"
},
"nodes": [
{
"id": "759d4f88-c6de-4cee-af9a-628102d93200",
"name": "📧 Gmail Webhook 触发器",
"type": "n8n-nodes-base.webhook",
"notes": "🔧 SETUP REQUIRED:\n1. Copy webhook URL after saving\n2. Configure Gmail webhook in Google Cloud Console\n3. Set up Gmail push notifications\n4. Test with sample email",
"position": [
-800,
464
],
"webhookId": "gmail-email-webhook",
"parameters": {
"path": "gmail-webhook",
"options": {},
"httpMethod": "POST",
"responseMode": "responseNode"
},
"typeVersion": 1
},
{
"id": "000229fb-153f-4db4-ad19-cda7b78f3b57",
"name": "📩 获取邮件详情",
"type": "n8n-nodes-base.gmail",
"notes": "🔧 SETUP REQUIRED:\n1. Create Gmail OAuth2 credentials\n2. Add scopes: gmail.readonly, gmail.modify\n3. Authorize the connection\n4. Test connection",
"position": [
-576,
464
],
"webhookId": "0d0edb78-408d-41be-b856-b3bdff6b4e4f",
"parameters": {
"messageId": "={{ $json.message.data.messageId }}",
"operation": "get"
},
"credentials": {
"gmailOAuth2": {
"id": "zDJ58xrpmivGPuAW",
"name": "Gmail account"
}
},
"typeVersion": 2
},
{
"id": "daf62cc0-3dc9-4b67-801b-3c48eeb3d4df",
"name": "🤖 AI 邮件分析器",
"type": "n8n-nodes-base.openAi",
"notes": "🔧 SETUP REQUIRED:\n1. Get OpenAI API key\n2. Add to credentials\n3. Choose model (gpt-4 recommended)\n4. Adjust temperature for consistency\n5. Test with sample emails",
"position": [
-368,
464
],
"parameters": {
"model": "gpt-4",
"prompt": "=Analyze this email and provide a JSON response with the following structure:\n{\n \"category\": \"urgent|important|promotional|spam|personal|work\",\n \"sentiment\": \"positive|negative|neutral\",\n \"priority\": \"high|medium|low\",\n \"action_needed\": \"reply|forward|archive|delete|flag\",\n \"summary\": \"brief summary in 1-2 sentences\",\n \"suggested_response\": \"suggested response if reply needed\",\n \"keywords\": [\"array\", \"of\", \"relevant\", \"keywords\"]\n}\n\nEmail details:\nFrom: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'From').value }}\nSubject: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'Subject').value }}\nBody: {{ $node['📩 Get Email Details'].json.snippet }}",
"options": {
"maxTokens": 1000,
"temperature": 0.3
},
"requestOptions": {}
},
"credentials": {
"openAiApi": {
"id": "OQJASLp1qn1StvpI",
"name": "OpenAi account"
}
},
"typeVersion": 1
},
{
"id": "cf1eba5b-6645-4b21-b5bb-d8cb4ae5015e",
"name": "🚦 优先级路由器",
"type": "n8n-nodes-base.if",
"notes": "📝 POST-IT NOTE:\nRoutes emails based on AI analysis\n- High priority → Immediate notification\n- Medium/Low → Standard processing\n- Customize conditions as needed",
"position": [
-144,
464
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": false,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ JSON.parse($json.choices[0].message.content).priority }}",
"rightValue": "high"
}
]
}
},
"typeVersion": 2
},
{
"id": "cbb52bdb-1065-4d4f-b09f-08e9367940f4",
"name": "🚨 高优先级警报",
"type": "n8n-nodes-base.gmail",
"notes": "🔧 SETUP REQUIRED:\n1. Update notification email address\n2. Customize alert message\n3. Consider using Slack/Teams instead\n4. Test notification delivery",
"position": [
80,
352
],
"webhookId": "76854229-c43b-4331-9860-d44d5e02b8ec",
"parameters": {
"message": "=High priority email received:\n\nFrom: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'From').value }}\nSubject: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'Subject').value }}\n\nAI Summary: {{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).summary }}\n\nSuggested Action: {{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).action_needed }}\n\nView in Gmail: https://mail.google.com/mail/u/0/#inbox/{{ $node['📩 Get Email Details'].json.id }}",
"options": {},
"subject": "🚨 High Priority Email Alert"
},
"credentials": {
"gmailOAuth2": {
"id": "zDJ58xrpmivGPuAW",
"name": "Gmail account"
}
},
"typeVersion": 2
},
{
"id": "b77a498a-001c-4029-a60a-1307dafa27fc",
"name": "🛡️ 垃圾邮件检测器",
"type": "n8n-nodes-base.if",
"notes": "📝 POST-IT NOTE:\nDetects spam emails\n- Auto-delete or move to spam\n- Log spam attempts\n- Update spam filters",
"position": [
80,
560
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": false,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).category }}",
"rightValue": "spam"
}
]
}
},
"typeVersion": 2
},
{
"id": "1b7b3f23-01cb-42c0-8985-79696d0a38b2",
"name": "🗑️ 移至垃圾邮件",
"type": "n8n-nodes-base.gmail",
"notes": "📝 POST-IT NOTE:\nMoves spam to spam folder\n- Removes from inbox\n- Adds spam label\n- Consider auto-delete after time",
"position": [
304,
656
],
"webhookId": "ca7a4755-b0f4-4f7e-9b3a-4c20971b2ce1",
"parameters": {
"operation": "modify"
},
"typeVersion": 2
},
{
"id": "63ae92b9-71c5-41e9-82f7-606985a1e4f3",
"name": "💬 自动回复检测器",
"type": "n8n-nodes-base.if",
"notes": "📝 POST-IT NOTE:\nDetects emails needing replies\n- AI suggests response\n- Option for auto-send or draft\n- Customize reply rules",
"position": [
304,
480
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": false,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).action_needed }}",
"rightValue": "reply"
}
]
}
},
"typeVersion": 2
},
{
"id": "778961c6-43d4-4624-abdb-3d6bebcf6249",
"name": "📝 创建回复草稿",
"type": "n8n-nodes-base.gmail",
"notes": "📝 POST-IT NOTE:\nCreates AI-generated reply draft\n- Review before sending\n- Customize response style\n- Option to auto-send for simple cases",
"position": [
528,
352
],
"webhookId": "2af91249-fdb6-4447-b573-8c06249a52fe",
"parameters": {
"message": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).suggested_response }}\n\n---\nThis is an AI-generated draft. Please review before sending.",
"options": {},
"subject": "=Re: {{ $node['📩 Get Email Details'].json.payload.headers.find(h => h.name === 'Subject').value }}",
"resource": "draft"
},
"typeVersion": 2
},
{
"id": "4a6f205f-80e6-42fc-be48-a672b76163ee",
"name": "🏷️ 邮件分类",
"type": "n8n-nodes-base.gmail",
"notes": "🔧 SETUP REQUIRED:\n1. Create Gmail labels:\n - URGENT, IMPORTANT\n - PROMOTIONAL, PERSONAL\n - WORK, PROJECTS\n2. Customize categories\n3. Set up label colors",
"position": [
528,
560
],
"webhookId": "8c0f452c-f1ac-4c72-8f92-834477ecd627",
"parameters": {
"operation": "modify"
},
"typeVersion": 2
},
{
"id": "9be9a801-9b54-45f2-a820-4a35dc7915bb",
"name": "📊 记录到电子表格",
"type": "n8n-nodes-base.googleSheets",
"notes": "🔧 SETUP REQUIRED:\n1. Create Google Sheets log\n2. Add headers: timestamp, messageId, from, subject, category, priority, sentiment, action_taken, ai_summary\n3. Share sheet with service account\n4. Update spreadsheet ID",
"position": [
752,
464
],
"parameters": {
"resource": "spreadsheet",
"operation": "appendOrUpdate"
},
"typeVersion": 4
},
{
"id": "0f78144e-bb3a-4065-b15e-3294750b13b7",
"name": "✅ Webhook 响应",
"type": "n8n-nodes-base.respondToWebhook",
"notes": "📝 POST-IT NOTE:\nSends response back to Gmail\n- Confirms processing\n- Includes analysis results\n- Required for webhook completion",
"position": [
960,
464
],
"parameters": {
"options": {},
"respondWith": "json",
"responseBody": {
"details": {
"category": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).category }}",
"priority": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).priority }}",
"messageId": "={{ $node['📩 Get Email Details'].json.id }}",
"action_taken": "={{ JSON.parse($node['🤖 AI Email Analyzer'].json.choices[0].message.content).action_needed }}"
},
"message": "Email processed successfully",
"success": true
}
},
"typeVersion": 1
},
{
"id": "fe23603a-8174-48ee-8ebf-3cabf507ecd7",
"name": "### 替换 Airtable 连接",
"type": "n8n-nodes-base.stickyNote",
"position": [
-768,
-320
],
"parameters": {
"color": 3,
"width": 576,
"height": 560,
"content": "## 需要定制工作流?告诉我您的业务需求,获取免费方案:"
},
"typeVersion": 1
},
{
"id": "4ca8fea5-6f43-41f9-9e68-e2dca7f73d8e",
"name": "便签10",
"type": "n8n-nodes-base.stickyNote",
"position": [
-464,
64
],
"parameters": {
"color": 3,
"width": 224,
"height": 128,
"content": "### 🛠️ 自己构建"
},
"typeVersion": 1
},
{
"id": "f2cbe293-04fa-48c4-8849-4637063becf3",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1776,
-304
],
"parameters": {
"width": 848,
"height": 2272,
"content": "# Gmail AI 邮件管理器 - 设置指南"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"🗑️ Move to Spam": {
"main": [
[
{
"node": "📊 Log to Spreadsheet",
"type": "main",
"index": 0
}
]
]
},
"🚦 Priority Router": {
"main": [
[
{
"node": "🚨 High Priority Alert",
"type": "main",
"index": 0
}
],
[
{
"node": "🛡️ Spam Detector",
"type": "main",
"index": 0
}
]
]
},
"🛡️ Spam Detector": {
"main": [
[
{
"node": "🗑️ Move to Spam",
"type": "main",
"index": 0
}
],
[
{
"node": "💬 Auto-Reply Detector",
"type": "main",
"index": 0
}
]
]
},
"📩 Get Email Details": {
"main": [
[
{
"node": "🤖 AI Email Analyzer",
"type": "main",
"index": 0
}
]
]
},
"🤖 AI Email Analyzer": {
"main": [
[
{
"node": "🚦 Priority Router",
"type": "main",
"index": 0
}
]
]
},
"📊 Log to Spreadsheet": {
"main": [
[
{
"node": "✅ Webhook Response",
"type": "main",
"index": 0
}
]
]
},
"📝 Create Reply Draft": {
"main": [
[
{
"node": "🏷️ Categorize Email",
"type": "main",
"index": 0
}
]
]
},
"🏷️ Categorize Email": {
"main": [
[
{
"node": "📊 Log to Spreadsheet",
"type": "main",
"index": 0
}
]
]
},
"💬 Auto-Reply Detector": {
"main": [
[
{
"node": "📝 Create Reply Draft",
"type": "main",
"index": 0
}
],
[
{
"node": "🏷️ Categorize Email",
"type": "main",
"index": 0
}
]
]
},
"🚨 High Priority Alert": {
"main": [
[
{
"node": "🏷️ Categorize Email",
"type": "main",
"index": 0
}
]
]
},
"📧 Gmail Webhook Trigger": {
"main": [
[
{
"node": "📩 Get Email Details",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 工单管理, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
基于 Outlook、OpenAI 和 JIRA 的 AI 支持自动化
集成 Outlook、OpenAI 和 JIRA 工单的 AI 支持自动化系统
If
Jira
Gmail
+9
18 节点Annie To
工单管理
竞争对手内容差距分析器:自动化网站主题映射
使用Gemini AI、Apify和Google Sheets分析竞争对手内容差距
If
Set
Code
+10
30 节点Mychel Garzon
杂项
来自多个招聘网站的求职自动化
使用 5 个招聘平台和 AI 简历生成器自动化求职与申请
If
Set
Code
+14
34 节点Gerald Denor
个人效率
票务后端
活动票务后端:使用Google Sheets和Gmail自动生成二维码门票
If
Code
Gmail
+7
35 节点Khairul Muhtadin
内容创作
使用PageSpeed Insights监控网站性能并保存到Google Sheets并发送警报
使用PageSpeed Insights监控网站性能,发送警报到Google Sheets
If
Set
Code
+8
20 节点Dahiana
开发运维
通过 OpenAI GPT-4o 进行 AI 内容生成,包含人工审核与一键批准工作流
使用GPT-4o简化内容创建,集成一键人工审核批准
If
Set
Code
+8
23 节点Cheng Siong Chin
内容创作
工作流信息
难度等级
中级
节点数量15
分类2
节点类型7
作者
Paul
@diagoplAutomation expert & n8n power user. I build advanced workflows combining AI, outbound, and business logic. Grab my templates or reach out for custom builds.
外部链接
在 n8n.io 查看 →
分享此工作流