# 用 n8n 和 Open Flow 模板自动分类 Gmail 并写入表格（附双版本 JSON）

Source: https://openflow.run/zh-cn/blog/gmail-classification-n8n-openflow-template/
Language: zh-CN

手动整理收件箱很难持续，但直接让不受约束的智能体去删改或归档邮件又太危险。更可控的做法是搭一条确定性工作流：定时轮询未读邮件、用 AI 节点把邮件归入固定分类并生成摘要，再写入 Google Sheets 供人工复核。

本文以 **Log Unread Gmail Classifications to Sheets** 模板为例，提供 **Open Flow** 与 **n8n** 双版本 JSON，你可以直接导入试跑。

## 这条工作流做什么

工作流每分钟轮询一次新的未读 Gmail 邮件（自动排除草稿、垃圾邮件与回收站，且不会把邮件标为已读或移动位置）：

1.  **检查未读邮件（Check new unread mail）**：获取新的未读邮件列表（Open Flow 单次轮询最多处理 100 封）。
2.  **读取邮件内容（Read the email）**：提取发件人、主题、日期与正文前 500 个字符。
3.  **AI 分类与摘要**：将邮件归入 `urgent`、`important`、`informational` 或 `spam` 四类，并生成一句摘要。
4.  **写入 Google Sheets**：将 `Date`、`From`、`Subject`、`Category` 和 `Summary` 追加到目标表格。

[Log Unread Gmail Classifications to Sheets](https://openflow.run/zh-cn/templates/log-unread-gmail-classifications-to-sheets/index.md "Log Unread Gmail Classifications to Sheets")[在 Open Flow 中使用](https://console.openflow.run/flows?importUrl=https%3A%2F%2Fraw.githubusercontent.com%2Foomol-lab%2Fawesome-workflow-templates%2F4ae2934012d3865e7d296909b9a06728464f1991%2Fworkflows%2Flog-unread-gmail-classifications-to-sheets%2Ftemplates%2Flog-unread-gmail-classifications-to-sheets.openflow.json)

Open Flow 邮件分类工作流预览。模板详情页同时提供 n8n 版本与完整配置说明。

## 获取双版本 JSON 模板

你可以直接在模板详情页查看说明、一键导入或下载对应的 JSON 文件：

*   **模板详情页**：[Log Unread Gmail Classifications to Sheets](https://openflow.run/zh-cn/templates/log-unread-gmail-classifications-to-sheets/index.md)
*   **一键导入 Open Flow**：[在 Open Flow 工作台打开](https://console.openflow.run/flows?importUrl=https%3A%2F%2Fraw.githubusercontent.com%2Foomol-lab%2Fawesome-workflow-templates%2F4ae2934012d3865e7d296909b9a06728464f1991%2Fworkflows%2Flog-unread-gmail-classifications-to-sheets%2Ftemplates%2Flog-unread-gmail-classifications-to-sheets.openflow.json)
*   **下载 Open Flow JSON**：[log-unread-gmail-classifications-to-sheets.openflow.json](https://raw.githubusercontent.com/oomol-lab/awesome-workflow-templates/4ae2934012d3865e7d296909b9a06728464f1991/workflows/log-unread-gmail-classifications-to-sheets/templates/log-unread-gmail-classifications-to-sheets.openflow.json)
*   **下载 n8n JSON**：[log-unread-gmail-classifications-to-sheets.n8n.json](https://raw.githubusercontent.com/oomol-lab/awesome-workflow-templates/4ae2934012d3865e7d296909b9a06728464f1991/workflows/log-unread-gmail-classifications-to-sheets/templates/log-unread-gmail-classifications-to-sheets.n8n.json)

## 所需账号与配置要求

| 准备项 | Open Flow 版本 | n8n 版本 |
| --- | --- | --- |
| **Gmail 账号** | 在 **Check new unread mail** 和 **Read the email** 节点连接同一个 Gmail 账号 | 在触发器与读取节点中配置 Gmail OAuth 凭据 |
| **Google Sheets** | 连接 Google Sheets，设置表格 ID 与范围 `'Lite Log'!A:E` | 连接 Google Sheets，在 **Log to Sheets** 中选择同一张表 |
| **AI 模型** | 直接使用统一的 OOMOL 账户额度，或自设 OpenAI 兼容地址 | 需单独注册并配置 OpenAI API Key 与账单 |
| **表格表头** | 第一行按顺序包含：`Date`、`From`、`Subject`、`Category`、`Summary` | 第一行按顺序包含：`Date`、`From`、`Subject`、`Category`、`Summary` |

## 导入与配置步骤

1.  **准备好目标表格**：新建一个 Google Sheet，工作表命名为 `Lite Log`，并在 `A` 到 `E` 列第一行依次填入 `Date`、`From`、`Subject`、`Category`、`Summary`。
2.  **选择一个版本导入**：打开[模板详情页](https://openflow.run/zh-cn/templates/log-unread-gmail-classifications-to-sheets/index.md)，点击一键导入 Open Flow，或下载 n8n JSON 导入你的 n8n 实例。
3.  **授权账号并启用**：完成 Gmail 与 Google Sheets 授权并检查 AI 模型配置。注意同一邮箱和表格只启用其中一个版本，避免重复写入。

## 测试输入与预期结果

用另一封邮箱向测试收件箱发送如下邮件（或将一封测试邮件标为未读）：

```text
From: billing-alerts@example-vendor.com
Subject: Action required: Payment failed for invoice #INV-2048
Body: Hi team, your card ending in 4242 was declined for invoice #INV-2048 ($490.00). Please update your payment method within 48 hours to avoid service interruption.
```

等待下一分钟的轮询触发后，`'Lite Log'!A:E` 中会追加如下一行记录：

| Date | From | Subject | Category | Summary |
| --- | --- | --- | --- | --- |
| `2026-11-18T10:05:00Z` | `billing-alerts@example-vendor.com` | `Action required: Payment failed for invoice #INV-2048` | `urgent` | Invoice #INV-2048 ($490.00) 扣款失败，需在 48 小时内更新付款方式以免服务中断。 |

## 两个版本在实际运行中的差异

虽然两者完成同一件事，但在运维细节上有两点区别：

*   **模型账号与计费**：Open Flow 通过同一个 OOMOL 账户直接调用 AI 模型（也支持自设端点），而 n8n 需要额外维护独立的 OpenAI API Key 与账单。
*   **表格写入失败处理**：两个版本都不会自动对表格行去重；当写入状态不确定时，Open Flow 会停止后续写入而不是盲目重试，避免把同一封邮件重复写进表格。

如果你想进一步评估两个平台的差异，可以阅读 [Open Flow vs n8n：哪一个更适合你？](https://openflow.run/zh-cn/blog/openflow-vs-n8n/index.md)。

OOMOL·2026年11月13日
