8
n8n 中文网amn8n.com

Gmail智能自动回复与分类系统

高级

这是一个Ticket Management, AI Summarization领域的自动化工作流,包含 18 个节点。主要使用 Gmail, GmailTrigger, GoogleSheets, OpenAi, LmChatOpenAi 等节点。 Gmail邮件分类与自动回复,使用GPT-4o和Google Sheets

前置要求
  • Google 账号和 Gmail API 凭证
  • Google Sheets API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "6MZqIrk7nB6lc4vB",
  "meta": {
    "instanceId": "15d6057a37b8367f33882dd60593ee5f6cc0c59310ff1dc66b626d726083b48d",
    "templateCredsSetupCompleted": true
  },
  "name": "Gmail 智能自动回复与分类系统",
  "tags": [],
  "nodes": [
    {
      "id": "9f88a550-a517-4362-a71f-b7997b9c75fa",
      "name": "Gmail 触发器",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -272,
        0
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "faf382e9-f898-447f-b5a1-d7a8c28d2309",
      "name": "文本分类器",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        -96,
        -32
      ],
      "parameters": {
        "options": {},
        "inputText": "={{ $json.text }}",
        "categories": {
          "categories": [
            {
              "category": "High Priority",
              "description": "Description: Emails that require immediate attention and could have a serious impact if delayed. Typical examples include: system outages, security alerts, critical legal notices, or urgent requests from executives or key clients. Examples: '[URGENT] Service outage notice', '[IMPORTANT] Contract renewal deadline'"
            },
            {
              "category": "Advertisement",
              "description": "Description: Marketing or promotional emails that do not require an immediate response. Typical examples include: sales announcements, product launches, newsletters, and event invitations. Examples: '[LIMITED OFFER] 50% off campaign', 'New service release announcement'"
            },
            {
              "category": "Inquiry",
              "description": "Description: Customer or partner inquiries that require a reply or follow-up. Typical examples include: product or service questions, quote requests, reservations, troubleshooting, repair or refund requests. Examples: 'Inquiry about studio reservation', 'Request for quotation'"
            },
            {
              "category": "Finance/Billing",
              "description": "Description: Emails related to payments, invoices, or financial transactions. Typical examples include: invoices, receipts, payment confirmations, bank or accounting notifications, and tax-related documents. Examples: 'Invoice submission notice', '[Payment confirmed] Thank you for your payment'"
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "aaddb0e0-fd5f-49ab-8887-f3ecc5bd9d89",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -96,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {
          "maxRetries": 1
        }
      },
      "credentials": {
        "openAiApi": {
          "id": "WBKhlscRuBMQi56k",
          "name": "OpenAi account 4"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "52265538-92f0-45b9-a7e8-78ba934620cf",
      "name": "保存优先邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        -240
      ],
      "webhookId": "18f19ef8-a4ec-4b1f-b3c6-4a9e7165eaff",
      "parameters": {
        "labelIds": [
          "Label_6395372519299544115"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "a3ac1d27-05ca-4832-bee9-176899915b27",
      "name": "保存广告邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        -48
      ],
      "webhookId": "18f19ef8-a4ec-4b1f-b3c6-4a9e7165eaff",
      "parameters": {
        "labelIds": [
          "Label_2877175876700118240"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "696b4433-3093-436c-b98d-2f910858823e",
      "name": "保存咨询邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        144
      ],
      "webhookId": "18f19ef8-a4ec-4b1f-b3c6-4a9e7165eaff",
      "parameters": {
        "labelIds": [
          "Label_8971387974199578288"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "68f89db1-59b8-4b15-8ac6-52354a28093a",
      "name": "保存财务邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        432,
        336
      ],
      "webhookId": "18f19ef8-a4ec-4b1f-b3c6-4a9e7165eaff",
      "parameters": {
        "labelIds": [
          "Label_7818902445747119871"
        ],
        "messageId": "={{ $json.id }}",
        "operation": "addLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "cdb0c68f-e041-47ef-b65e-14e2c476a760",
      "name": "生成优先草稿",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        -240
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are an executive assistant.  \nYour task is to reply accurately to high-priority incoming emails.  \nHere is the email you need to respond to: {{ $('Gmail Trigger').item.json.text }}  \n\nPlease output the following parameters:\n- Subject  \n- Message\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "id": "lHkSeZk3nuftEHri",
          "name": "デモ"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "a59b0fc2-b11e-4e9c-a5c6-b5aa33f85bac",
      "name": "生成广告摘要",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        -48
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a marketing specialist.  \nYour task is to summarize incoming promotional or marketing emails concisely in 1–2 lines for spreadsheet logging.  \n\nHere is the received email: {{ $('Gmail Trigger').item.json.text }}\n\nPlease extract and summarize the following fields:\n- Sender  \n- Subject  \n- Summary  \n- Recommendation\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "id": "WBKhlscRuBMQi56k",
          "name": "OpenAi account 4"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "64f4df61-ee88-4ea0-857f-7d738c2f3c21",
      "name": "生成财务摘要",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        144
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a customer service representative.  \nYour task is to reply accurately to customer inquiries.  \nIf the question cannot be answered, instruct the sender to contact the following number: 000-0000-000.  \n\nHere is the email you need to respond to: {{ $('Gmail Trigger').item.json.text }}\n\nPlease output the following parameters:\n- Subject  \n- Message\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "id": "WBKhlscRuBMQi56k",
          "name": "OpenAi account 4"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "a8df46ff-73f7-4129-94cb-0f452b328716",
      "name": "生成咨询回复",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        640,
        336
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "GPT-4O"
        },
        "options": {},
        "messages": {
          "values": [
            {
              "content": "=You are a finance and billing assistant.  \nYour task is to summarize emails related to invoices, payments, and financial notifications in a concise manner.  \n\nHere is the received email: {{ $('Gmail Trigger').item.json.text }}\n\nPlease output the following parameters:\n- Subject  \n- Message\n"
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "id": "WBKhlscRuBMQi56k",
          "name": "OpenAi account 4"
        }
      },
      "executeOnce": false,
      "typeVersion": 1.8,
      "alwaysOutputData": false
    },
    {
      "id": "ef15e762-463f-4acd-9c38-cb84735c9feb",
      "name": "创建草稿",
      "type": "n8n-nodes-base.gmail",
      "position": [
        992,
        -240
      ],
      "webhookId": "e203a0df-3a0f-48fc-9581-684beb49c073",
      "parameters": {
        "message": "={{ $json.message.content['message'] }}",
        "options": {},
        "subject": "={{ $json.message.content['send'] }}",
        "resource": "draft"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "45aa5109-f0c2-43e7-a91a-db0fcc109cc7",
      "name": "添加行到表格",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        992,
        -48
      ],
      "parameters": {
        "columns": {
          "value": {
            "Sender": "={{ $json.message.content['Sender'] }}",
            "Subject": "={{ $json.message.content['Subject'] }}",
            "Summary": "={{ $json.message.content['Summary'] }}",
            "Recommendation": "={{ $json.message.content['Recommendation'] }}"
          },
          "schema": [
            {
              "id": "Sender",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Sender",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Recommendation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Recommendation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13AmknC94wJ5n1FDl7E1yUFsCNYVDJklzPpTZmFQrMb4/edit#gid=0",
          "cachedResultName": "01_Advertisement Mail Summary"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "13AmknC94wJ5n1FDl7E1yUFsCNYVDJklzPpTZmFQrMb4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/13AmknC94wJ5n1FDl7E1yUFsCNYVDJklzPpTZmFQrMb4/edit?usp=drivesdk",
          "cachedResultName": "[n8n] Advertisement Mail Summary"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "Ja0tGvoFNudNwqMM",
          "name": "md83 H2"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "6701a84f-2e2a-42f2-9c98-fb7ee3f394f1",
      "name": "发送财务邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        992,
        144
      ],
      "webhookId": "0256a9d5-e87f-499e-98c4-ced9e9b6f204",
      "parameters": {
        "message": "={{ $json.message.content['message'] }}",
        "options": {},
        "resource": "thread",
        "threadId": "={{ $('Save Inquiry Mail').item.json.threadId }}",
        "messageId": "={{ $('Save Inquiry Mail').item.json.id }}",
        "operation": "reply"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "89129a16-1f1a-48e4-82f1-0593c142909b",
      "name": "回复咨询",
      "type": "n8n-nodes-base.gmail",
      "position": [
        992,
        336
      ],
      "webhookId": "01d72fbe-d12c-4992-9977-7aa4316e0af0",
      "parameters": {
        "sendTo": "{{YOUR_EMAIL_ADDRESS}}",
        "message": "={{ $json.message.content['message'] }}",
        "options": {},
        "subject": "={{ $json.message.content['send'] }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "NdoEDipkhQPaRDuy",
          "name": "Gmail account 6"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "6f1a41f5-ad3e-4b4b-906d-44a20bbe0623",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        -304
      ],
      "parameters": {
        "width": 416,
        "height": 880,
        "content": "## 📩Gmail 智能自动回复与分类系统 (LangChain + OpenAI + Google Sheets)"
      },
      "typeVersion": 1
    },
    {
      "id": "49d044e4-0a1c-4fff-b205-77d43db01251",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -176
      ],
      "parameters": {
        "color": 2,
        "width": 512,
        "height": 496,
        "content": "## ①接收 Gmail → AI 理解邮件内容"
      },
      "typeVersion": 1
    },
    {
      "id": "904ff69b-74bc-4c26-aa3d-5af797548e7e",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        272,
        -624
      ],
      "parameters": {
        "width": 960,
        "height": 1200,
        "content": "## ②邮件处理部分"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "fa5d38ad-f0cb-4b9a-962d-295da7453ed7",
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Text Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Text Classifier": {
      "main": [
        [
          {
            "node": "Save Priority Mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Advertisement Mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Inquiry Mail",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Finance Mail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Text Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Save Finance Mail": {
      "main": [
        [
          {
            "node": "Generate Inquiry Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Inquiry Mail": {
      "main": [
        [
          {
            "node": "Generate Finance Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Priority Mail": {
      "main": [
        [
          {
            "node": "Generate Priority Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Ad Summary": {
      "main": [
        [
          {
            "node": "Append Row to Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Inquiry Reply": {
      "main": [
        [
          {
            "node": "Reply to Inquiry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Priority Draft": {
      "main": [
        [
          {
            "node": "Create Draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Advertisement Mail": {
      "main": [
        [
          {
            "node": "Generate Ad Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Finance Summary": {
      "main": [
        [
          {
            "node": "Send Finance Mail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 工单管理, AI 摘要总结

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量18
分类2
节点类型7
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

外部链接
在 n8n.io 查看

分享此工作流