8
n8n 中文网amn8n.com

Gmail AI自动回复

中级

这是一个Multimodal AI领域的自动化工作流,包含 11 个节点。主要使用 If, Set, Gmail, GmailTrigger, Agent 等节点。 Gmail自动回复生成器,使用GPT-4o-mini

前置要求
  • Google 账号和 Gmail API 凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "name": "Gmail AI 自动回复",
  "tags": [],
  "nodes": [
    {
      "id": "50972917-6da6-4b55-b18b-0bd96445e9f8",
      "name": "新邮件触发",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        0,
        -352
      ],
      "parameters": {
        "filters": {
          "readStatus": "unread"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "f42bb871-a182-4708-aa12-65f6c9c5ee28",
      "name": "获取未读邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        224,
        -352
      ],
      "parameters": {
        "simple": false,
        "options": {},
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "typeVersion": 2.1
    },
    {
      "id": "c0ce4d37-a5ce-4926-9edf-5aa68d80426a",
      "name": "获取必填字段",
      "type": "n8n-nodes-base.set",
      "position": [
        448,
        -352
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "name": "threadId",
              "type": "string",
              "value": "={{ $json.threadId }}"
            },
            {
              "name": "id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "name": "From",
              "type": "string",
              "value": "={{ $json.headers.from }}"
            },
            {
              "name": "message",
              "type": "string",
              "value": "={{ $json.text }}"
            },
            {
              "name": "subject",
              "type": "string",
              "value": "={{ $json.subject }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "64d9c2c7-0ef8-49f2-9c6c-5b0aabd27112",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        672,
        -352
      ],
      "parameters": {
        "text": "=You are an assistant that helps draft email replies.\n\nYour task:\n1. Read the email message below:\n\"{{ $json.message }}\"\n\n2. Decide if this is an email that requires a reply.  \n   - If it's spam, a notification, or irrelevant, set `isReply` to false.  \n   - If it's a genuine message that can be replied to, set `isReply` to true.  \n\n3. If `isReply` is true, draft a short and polite reply that:  \n   - Acknowledges the sender.  \n   - Is under 120 words.  \n   - Does not promise action you cannot take.  \n\n4. Return the result **only in valid JSON**, no extra text.\n\nJSON format to return:\n{\n  \"isReply\": true | false,\n  \"response\": \"string or empty if isReply is false\"\n}",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "5673e94b-82b0-407f-9db4-60b35dfb8253",
      "name": "OpenAI",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        680,
        -128
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "00fe0a38-cc10-492e-86d6-af0494c8afc9",
      "name": "Structured Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        808,
        -128
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"isReply\": {\n      \"type\": \"boolean\",\n      \"description\": \"Whether the email requires a reply\"\n    },\n    \"response\": {\n      \"type\": \"string\",\n      \"description\": \"The drafted reply text if isReply is true, otherwise empty\"\n    }\n  },\n  \"required\": [\"isReply\", \"response\"]\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "7fd55349-a8a3-4c1b-8dc8-221a50915a5e",
      "name": "AI Agent 能否回复?",
      "type": "n8n-nodes-base.if",
      "position": [
        1024,
        -352
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.isReply }}",
              "rightValue": "true"
            }
          ]
        },
        "looseTypeValidation": true
      },
      "typeVersion": 2.2
    },
    {
      "id": "ba0480ca-4f1d-4813-b6d8-674ec1f2bafe",
      "name": "创建草稿",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1248,
        -352
      ],
      "parameters": {
        "message": "={{ $json.output.response }}",
        "options": {
          "threadId": "={{ $('Get Required Fields').item.json.threadId }}"
        },
        "subject": "={{ $('Get Required Fields').item.json.subject }}",
        "resource": "draft"
      },
      "typeVersion": 2.1
    },
    {
      "id": "be177f90-54e7-472f-8b30-3dd6c8c1f4a3",
      "name": "标记邮件为\"待处理\"",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1472,
        -352
      ],
      "parameters": {
        "labelIds": [
          "Label_4601850039988562325"
        ],
        "resource": "thread",
        "threadId": "={{ $('Get Required Fields').item.json.threadId }}",
        "operation": "addLabels"
      },
      "typeVersion": 2.1
    },
    {
      "id": "434ebfe4-410a-4f49-9285-cfd6256abb6f",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -192,
        0
      ],
      "parameters": {
        "width": 336,
        "content": "## 🛠️ 设置说明"
      },
      "typeVersion": 1
    },
    {
      "id": "77831399-3e74-454e-8e27-b9d6e2af638c",
      "name": "便签 1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        608,
        -576
      ],
      "parameters": {
        "color": 5,
        "width": 368,
        "height": 656,
        "content": "## ⚠️ 回复逻辑"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "OpenAI": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Can AI Agent Respond?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a draft": {
      "main": [
        [
          {
            "node": "Label Email As \"Action\"",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Unread Email": {
      "main": [
        [
          {
            "node": "Get Required Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Get Required Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger on New Email": {
      "main": [
        [
          {
            "node": "Get Unread Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Can AI Agent Respond?": {
      "main": [
        [
          {
            "node": "Create a draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 多模态 AI

需要付费吗?

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

工作流信息
难度等级
中级
节点数量11
分类1
节点类型8
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Matt Chong | n8n Creator

Matt Chong | n8n Creator

@mattxchong

Automation nerd fueled by good coffee, deep curiosity, and clean flows.

外部链接
在 n8n.io 查看

分享此工作流