ChatGPT销售客服AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

用 n8n 自动分析、分类并总结 Gmail 邮件(OpenAI RAG + Google Sheets)

Gmail 新邮件触发 → 提取清洗 → RAG 向量检索分类 → Google Sheets 存储 → 自学习分类法更新 → Telegram 音频摘要通知

有一点经验步骤流程提示词贴士
给谁
需要自动化处理大量 Gmail 邮件、并按自定义分类法归档的销售/客服/运营人员
你会得到
新邮件到达后自动提取内容,通过 RAG 检索历史分类示例进行 AI 分类与摘要,结果写入 Google Sheets,同时生成音频摘要推送至 Telegram;遇到新类别时自动扩展分类法并通知管理员
你需要
n8n · gmail · google-sheets · telegram

硬约束

前置条件:n8n 实例(Cloud 或自托管)、Google 账号(Gmail + Sheets)、OpenAI API 账号、Telegram Bot。所需凭证类型:Gmail OAuth2、Google Sheets OAuth2、OpenAI API、Telegram API。首次运行需手动执行一次以填充向量存储。费用取决于 OpenAI API 调用量与 n8n 托管方案。

他们做了什么

作者 amirhoseinzahedi 在 n8n 模板库发布了一个工作流模板。该模板通过 Gmail Trigger 监听新邮件,提取并清洗邮件内容后,利用 Google Sheets 中的历史分类示例构建内存向量存储,作为 RAG 知识库。AI Agent(OpenAI gpt-4.1-mini)在系统提示词约束下,优先依据检索到的分类示例进行邮件分类、摘要、关键词提取和置信度打分,输出严格 JSON。解析后的数据存入 Google Sheets,若检测到新类别或子类别,则自动扩展分类法数据集并通过 Telegram 通知管理员。同时,系统生成 OpenAI 音频摘要并推送至 Telegram。

效果如何

来源报告(author_report):该模板实现了全自动 Gmail 监控、RAG 邮件分类、分类法一致性强制、自动关键词提取与置信度评分、自更新分类知识库、Google Sheets 邮件数据库、AI 语音摘要、Telegram 管理员通知,以及持续改进的分类准确率。模板在 n8n.io 上发布,状态为 published,创建时间 2026-02-21。

值得知道

1. 本站未对该模板进行实际运行验证(reproduction=not_tested),搭建效果取决于凭证配置和 API 可用性。 2. 向量存储为内存型(in-memory),n8n 实例重启后可能需要重新初始化;来源建议首次手动运行以填充数据。 3. 来源中的 Google Sheets documentId 和 Telegram chatId 为模板占位符,必须替换为真实值才能正常工作。 4. 分类法质量高度依赖 Tagging Samples 的初始示例数量和代表性;示例不足时分类效果会下降。 5. OpenAI 音频生成(tts)按字符计费,高频邮件场景需注意费用控制。 6. 该模板使用 n8n 的 AI Agent 节点(LangChain 集成),需要 n8n 版本支持 LangChain 节点;具体版本要求未在来源中明确。 7. 系统提示词要求输出严格 JSON,但实际运行中仍可能因模型原因出现格式错误,建议在 Parse AI analysis result 前增加错误处理或 JSON 修复节点(来源未提供,属本站建议)。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • OpenAI Chat Model 节点:绑定OpenAI API 凭证。
  • Gmail Trigger 节点:绑定Gmail OAuth2 凭证。
  • Get row(s) in sheet 节点:绑定Google Sheets OAuth2 凭证。
  • Fetch full Gmail message 节点:绑定Gmail OAuth2 凭证。
  • Store processed email 节点:绑定Google Sheets OAuth2 凭证。
  • Load taxonomy dataset 节点:绑定Google Sheets OAuth2 凭证。
  • Append new taxonomy entry 节点:绑定Google Sheets OAuth2 凭证。
  • Notify admin about taxonomy update 节点:绑定Telegram API 凭证。
  • Generate audio summary 节点:绑定OpenAI API 凭证。
  • Send audio summary to Telegram 节点:绑定Telegram API 凭证。
  • Create embeddings (OpenAI) 节点:绑定OpenAI API 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #13568(约 29 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-24

步骤

  1. 配置触发器与凭证

    在 n8n 中创建以下凭证:Gmail OAuth2(用于触发和读取邮件)、Google Sheets OAuth2(用于存储和分类法数据集)、OpenAI API(用于聊天、嵌入和音频生成)、Telegram API(用于通知)。添加 Gmail Trigger 节点,设置为每分钟轮询新邮件。添加 Fetch full Gmail message 节点,使用 messageId 获取完整邮件内容。

  2. 提取并规范化邮件字段

    添加 Normalize email fields(Edit Fields/Set)节点,从原始邮件中提取并映射以下字段:id、date、sender(from.value[0].name)、email(from.value[0].address)、subject、content(使用 html.removeTags() 去除 HTML 标签)。确保输出为纯文本,供后续 AI 节点处理。

  3. 准备 RAG 分类法知识库(首次手动运行)

    在 Google Sheets 中创建两个工作表:Sheet 1「Email Log」含列 date、email、name、subject、summarized text、category、subcategory、keywords;Sheet 2「Tagging Samples」含列 id、subject、email_text、category、subcategory、keywords。添加 Get row(s) in sheet 节点读取 Tagging Samples 全表;添加 Prepare taxonomy documents 节点将 subject 与 email_text 拼接为文档;添加 Create embeddings (OpenAI) 节点生成向量嵌入;添加 Vector store — taxonomy index 节点以 insert 模式写入内存向量库(memoryKey=email_tagging)。添加 Vector store retriever (RAG tool) 节点以 retrieve-as-tool 模式供 Agent 调用(topK=1)。首次需手动点击「Execute workflow」运行此分支以填充向量存储。

  4. 配置 AI 分析 Agent(RAG 分类与摘要)

    添加 Analyze email with RAG agent 节点(AI Agent),连接 OpenAI Chat Model(gpt-4.1-mini)作为语言模型,连接 Vector store retriever 作为工具。在 Agent 的 text 字段输入邮件变量,在 options.systemMessage 粘贴系统提示词。该提示词要求模型:用向量存储检索到的示例作为分类法唯一真相来源,优先使用已有类别,仅在无合理匹配时创建新类别;输出严格 JSON,附加 summary、short_message、category、subcategory、keywords、confidence、new_category、new_subcategory 字段;并在最终输出前做内部校验。

    运行提示词 · 来源原文。AI Agent 节点的 text 输入字段(User Message),需保留 n8n 表达式语法

    =sender: {{ $json.sender }}
    email: {{ $json.email }}
    date: {{ $json.date }}
    subject: {{ $json.subject }}
    content: {{ $json.content }}

    运行提示词 · 来源原文。AI Agent 节点的 options.systemMessage 字段(System Prompt)

    =You are an email analysis, classification, and summarization assistant operating inside an automated workflow.
    
    You will receive ONE incoming email object as input.
    
    Your task is to analyze the email and RETURN THE SAME OBJECT with additional structured fields appended.
    
    --------------------------------------------------
    PRIMARY OBJECTIVES
    --------------------------------------------------
    
    1. Summarize the email content in ONE short paragraph (maximum 3 sentences).
    
    2. Classify the email using semantic context retrieved from "Simple Vector Store1".
    
    3. The retrieved examples represent the OFFICIAL taxonomy and are the PRIMARY SOURCE OF TRUTH for categories and subcategories.
    
    4. Extract up to 5 meaningful keywords representing the main topics of the email.
    
    5. Provide a confidence score between 0 and 1 indicating classification certainty.
    
    --------------------------------------------------
    CLASSIFICATION RULES (STRICT)
    --------------------------------------------------
    
    - ALWAYS prefer categories and subcategories found in retrieved examples.
    - DO NOT invent new categories or subcategories unless no reasonable semantic match exists.
    - Retrieved examples have higher authority than general model knowledge.
    - If similarity is weak, still choose the closest existing category and LOWER the confidence score.
    - Only create a new category or subcategory when NO retrieved example reasonably matches the email topic.
    
    Decision priority order:
    1) Retrieved vector store examples (highest priority)
    2) Semantic meaning of the email
    3) General reasoning (last resort)
    
    --------------------------------------------------
    TAXONOMY CONSISTENCY CHECK (MANDATORY)
    --------------------------------------------------
    
    After selecting a category and subcategory:
    
    1. Compare the selected category against ALL categories present in the retrieved examples from "Simple Vector Store1".
    
    2. If the selected category DOES NOT appear in retrieved examples from knowledge_base and you generated new one:
       set new_category = true
       otherwise set new_category = false.
    
    3. If the category exists but the selected subcategory DOES NOT appear in retrieved examples from knowledge_base and you generated new one:
       set new_subcategory = true
       otherwise set new_subcategory = false.
    
    4. This decision MUST be based ONLY on retrieved examples, not on general knowledge.
    
    --------------------------------------------------
    CONFIDENCE SCORING
    --------------------------------------------------
    
    0.90–1.00 → strong semantic match with retrieved examples
    0.70–0.89 → clear topic with minor ambiguity
    0.50–0.69 → weak similarity but reasonable classification
    0.00–0.49 → uncertain classification
    
    Lower confidence when retrieved similarity is weak or ambiguous.
    
    --------------------------------------------------
    OUTPUT REQUIREMENTS (CRITICAL)
    --------------------------------------------------
    
    - Output MUST be valid JSON ONLY.
    - DO NOT include markdown, explanations, comments, or extra text.
    - DO NOT remove, rename, or modify any existing input fields.
    - Preserve all original fields exactly as received.
    - Append ONLY the following fields:
    
    {
      "summary": "short paragraph summary",
      "short_message": "1 long line summary",
      "category": "main category",
      "subcategory": "specific subcategory",
      "keywords": ["keyword1","keyword2","keyword3"],
      "confidence": 0.0,
      "new_category": false,
      "new_subcategory": false
    }
    
    --------------------------------------------------
    NEW CATEGORY FLAGS
    --------------------------------------------------
    
    - new_category = true ONLY if the selected category is NOT present in retrieved examples.
    - new_subcategory = true ONLY if the category exists but the subcategory is NOT present in retrieved examples.
    
    --------------------------------------------------
    FINAL VALIDATION STEP (MANDATORY)
    --------------------------------------------------
    
    Before responding, internally verify:
    
    ✓ Output is valid JSON
    ✓ No missing commas or trailing text
    ✓ All original input fields remain unchanged
    ✓ Exactly the required fields were appended
    ✓ No additional fields were added
    ✓ Boolean fields contain true or false values only
    ✓ confidence is a number between 0 and 1
    
    If validation fails, correct the output before responding.
  5. 解析结果并存储到 Google Sheets

    添加 Parse AI analysis result(Edit Fields/Set)节点,使用 parseJson() 解析 Agent 的 JSON 输出,映射为 sender、email、date、subject、content(summary)、short message、category、subcategory、keyword(keywords.join())、confidence、new category、new subcategory。随后添加 Store processed email(Google Sheets)节点,以 append 模式写入 Email Log 工作表,字段映射与步骤 3 中 Sheet 1 的列结构一致。

  6. 自学习分类法更新与管理员通知

    添加 Check for new taxonomy items(If)节点,判断 new category 或 new subcategory 是否为 "true"。若为真,走「true」分支:添加 Load taxonomy dataset 读取现有 Tagging Samples;添加 Get next taxonomy ID(Code 节点,Python)计算最大 id;添加 Append new taxonomy entry 将新类别/子类别写入 Tagging Samples;添加 Notify admin about taxonomy update(Telegram)发送文字通知。

    运行提示词 · 来源原文。Telegram 节点 Notify admin about taxonomy update 的 text 字段

    =New category/subcategory added:
    {{ $json.category }} / {{ $json.subcategory }}
  7. 生成音频摘要并推送 Telegram

    在 Check for new taxonomy items 的「false」分支(或直接并行)添加 Generate audio summary(OpenAI)节点,resource 设为 audio,input 取 Store processed email 的 summarized text。再添加 Send audio summary to Telegram 节点,operation 设为 sendAudio,binaryData=true,caption 包含发件人、格式化日期、主题,fileName 设为 "email bite"。chatId 需替换为实际 Telegram 用户或群组 ID。

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限,再按步骤复现工作流

这一段是提示词,页面不会在这里插入广告。

你正在搭建一个 n8n 工作流,用于自动分析、分类和总结 Gmail 邮件。请按以下顺序确认并执行:
1. 检查你是否已具备:n8n 实例、Google 账号(Gmail + Sheets)、OpenAI API key、Telegram Bot token 与 chat ID。
2. 在 n8n 中创建四个凭证:Gmail OAuth2、Google Sheets OAuth2、OpenAI API、Telegram API。
3. 按步骤说明在 Google Sheets 中创建 Email Log 和 Tagging Samples 两个工作表,并填入初始分类示例。
4. 导入或按 workflow.json 重建节点连线,特别注意:AI Agent 的 systemMessage 和 text 字段必须逐字复制;Vector store 的 memoryKey 统一为 email_tagging;首次运行需手动执行以填充向量存储。
5. 将 Telegram 节点中的 [YOUR_CHAT_ID] 替换为真实 ID。
6. 激活工作流后,发送一封测试邮件,验证:邮件是否出现在 Email Log、类别是否正确、Telegram 是否收到音频摘要。

首次运行必须手动执行一次以填充向量存储;Telegram chatId 和 Google Sheets documentId 需替换为你自己的值;OpenAI 音频生成会产生额外费用。

来源

Analyze, classify, and summarize Gmail with OpenAI RAG and Google Sheets · amirhoseinzahedi · n8n.io · 2026-02-21

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例