8
n8n 中文网amn8n.com

第二个 Gmail 草稿和发送

高级

这是一个Ticket Management, Multimodal AI领域的自动化工作流,包含 18 个节点。主要使用 Gmail, Switch, GmailTrigger, Agent, LmChatGoogleGemini 等节点。 使用 Gemini AI 和 Gmail 实现智能邮件回复自动化管理

前置要求
  • Google 账号和 Gmail API 凭证
  • Google Gemini API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "yAmWWzUXTwmC6hPO",
  "meta": {
    "instanceId": "679a5e6996c7b87733ea9da67669642511fe2f1215d268a884919abfbd13ffdb",
    "templateCredsSetupCompleted": true
  },
  "name": "第二个 Gmail 草稿和发送",
  "tags": [],
  "nodes": [
    {
      "id": "04005997-5f22-40f8-b1c5-8791b106d277",
      "name": "标记为人工审核",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -48,
        480
      ],
      "webhookId": "f391c634-6d29-44eb-b122-e40c93df2cd0",
      "parameters": {
        "message": "={{ $json.output }}",
        "options": {
          "sendTo": "={{ $('Get a message').item.json.from.value[0].address }}",
          "threadId": "={{ $('Get a message').item.json.threadId }}"
        },
        "subject": "={{ $('Get a message').item.json.subject }}",
        "resource": "draft"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "PuAE61pOClI4CRxE",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "57d5d8fd-3391-4af0-9305-2249d4885f5f",
      "name": "Gmail 触发器",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1648,
        240
      ],
      "parameters": {
        "simple": false,
        "filters": {},
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "PuAE61pOClI4CRxE",
          "name": "Gmail account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "55ee3c91-fa91-44eb-ad28-87c2a614f2a1",
      "name": "Google Gemini 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -1168,
        416
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash-preview-05-20"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "7X1ZyvDFg4ocTHrj",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "af2b05c9-5229-4027-a514-0d210ea26fe7",
      "name": "AI 分类器",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -1168,
        240
      ],
      "parameters": {
        "text": "=You are an AI assistant that drafts helpful email replies. For each incoming email, you will draft a reply and classify whether the email is 'simple' (can be auto-replied) or 'complex' (requires human review) or needs nothing to do.\n\nRules for classification:\n\n\nIf the email contains any sensitive topic (e.g: personal data such as biometric data, health records, racial or ethnic origin, religious or philosophical beliefs, political opinions, and sexual orientation, financial data (account numbers, credit card information), government identifiers (Social Security Numbers), and company-specific data such as trade secrets and strategic plans, etc.). classify it as \"draft\".\n\nAnd if the email does not contain any of the sensitive information and is a normal email and needs a reply, classify it as \"Reply\".\n\nAnd if an email does not contain any of the topic or information that does need reply (e.g, marketing or spam, automated notifications like \"do not reply\" emails or pickup alerts, transactional messages such as purchase receipts or account verification, and emails with no clear call to action that could bury important messages for recipients. In general, if a message is purely informational, doesn't ask for action, or is from an unknown source.) Classify it as \"Nothing\".\n\nProvide the Category Only: Respond with the category name and nothing else. Do not add any extra text, explanations, or commentary. Your response should be a single word. and you have 3 categories: \n\n1. Draft\n2. Reply\n3. Nothing\n\nHere is the Email:\n\n{{ $json.text }}",
        "options": {
          "batching": {
            "batchSize": 1,
            "delayBetweenBatches": 0
          },
          "passthroughBinaryImages": true,
          "returnIntermediateSteps": false
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "9a53a9bf-9665-4f5c-a0b9-74f5421509f5",
      "name": "Gemini 聊天草稿",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -384,
        640
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash-preview-05-20"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "7X1ZyvDFg4ocTHrj",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "75bda556-8de8-462d-8ca6-a3fc30ca3436",
      "name": "Gemini 聊天回复",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        -384,
        192
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash-preview-05-20"
      },
      "credentials": {
        "googlePalmApi": {
          "id": "7X1ZyvDFg4ocTHrj",
          "name": "Google Gemini(PaLM) Api account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5396f107-619c-426d-b759-ebece261871f",
      "name": "无操作,不执行任何操作",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -688,
        560
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "dd50a20e-869e-4e9e-9c07-820be5fa9f95",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1712,
        48
      ],
      "parameters": {
        "width": 448,
        "height": 400,
        "content": "## Gmail 触发器 + 获取消息"
      },
      "typeVersion": 1
    },
    {
      "id": "1c0fdd25-c89d-4ee8-a83e-7f0b455921e8",
      "name": "获取消息",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1424,
        240
      ],
      "webhookId": "b6b6ae33-af63-423a-b24d-70f9c8ccb73c",
      "parameters": {
        "simple": false,
        "options": {},
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "PuAE61pOClI4CRxE",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "09f432ed-6285-4147-92d5-2b645912098d",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1232,
        -112
      ],
      "parameters": {
        "width": 400,
        "height": 704,
        "content": "## Google Gemini 聊天模型 + AI 分类器"
      },
      "typeVersion": 1
    },
    {
      "id": "53e0e46b-f29f-45d0-a417-df2fdf1f56bb",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        -144
      ],
      "parameters": {
        "width": 320,
        "height": 608,
        "content": "## 回复、草稿或无操作(条件分支)"
      },
      "typeVersion": 1
    },
    {
      "id": "c4d14987-f859-4983-9adc-7e326554262c",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        -240
      ],
      "parameters": {
        "width": 672,
        "height": 576,
        "content": "## 生成邮件回复 + Gemini 聊天回复 + 回复"
      },
      "typeVersion": 1
    },
    {
      "id": "2664562a-abe4-4857-ab53-82b8726a57ce",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -800,
        496
      ],
      "parameters": {
        "width": 320,
        "height": 400,
        "content": "## 无操作,不执行任何操作"
      },
      "typeVersion": 1
    },
    {
      "id": "447df387-dbca-40eb-990e-2d22906a0447",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -448,
        432
      ],
      "parameters": {
        "width": 672,
        "height": 592,
        "content": "## 生成草稿邮件 + Gemini 聊天草稿 + 标记为人工审核"
      },
      "typeVersion": 1
    },
    {
      "id": "6ec6fb16-1f87-408d-8bd2-9211384cea2b",
      "name": "回复、草稿或无操作",
      "type": "n8n-nodes-base.switch",
      "position": [
        -736,
        224
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "68b68c40-f028-4431-9940-66543b04578a",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output }}",
                    "rightValue": "Reply"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7df0c8a2-3616-4e84-9af3-14a2e637cb7c",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output }}",
                    "rightValue": "Draft"
                  }
                ]
              }
            },
            {
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "799f30a4-15c6-45cb-8617-d9e2fe148536",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.output }}",
                    "rightValue": "Nothing"
                  }
                ]
              }
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "a4e6e81d-de73-4562-b37e-dfab96ba5fc4",
      "name": "生成草稿邮件",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -384,
        480
      ],
      "parameters": {
        "text": "=Reply to the email I give you in a warm, polite, and professional tone. Write like a thoughtful human—use natural phrasing, gentle transitions, and avoid robotic or overly formal wording. Address all points clearly, keep it concise, and maintain a friendly, respectful feel. Reply must be easy to read. and don't output subject line, only output the reply. My name is hashir. must keep an eye on one thing, don't add in the reply anything like this \"[Your Company Name]\" etc. its a final reply so don't add anything that that needs any manual addition or editing. Output the final reply.\n\nHere is the Subject line: {{ $('Get a message').item.json.headers.subject }}\n\nHere is the Email:\n\n{{ $('Get a message').item.json.text }}",
        "options": {
          "batching": {
            "batchSize": 1,
            "delayBetweenBatches": 0
          },
          "passthroughBinaryImages": true,
          "returnIntermediateSteps": false
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "65df0884-ef4d-483b-a8d4-a9ba0e252f94",
      "name": "生成邮件回复",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -384,
        32
      ],
      "parameters": {
        "text": "=Reply to the email I give you in a warm, polite, and professional tone. Write like a thoughtful human—use natural phrasing, gentle transitions, and avoid robotic or overly formal wording. Address all points clearly, keep it concise, and maintain a friendly, respectful feel. Reply must be easy to read. and don't output subject line, only output the reply. My name is hashir. must keep an eye on one thing, don't add in the reply anything like this \"[Your Company Name]\" etc. its a final reply so don't add anything that needs any manual addition or editing. Output the final reply.\n\nHere is the Subject line: {{ $('Get a message').item.json.headers.subject }}\n\nHere is the Email:\n\n{{ $('Get a message').item.json.text }}",
        "options": {
          "passthroughBinaryImages": true,
          "returnIntermediateSteps": false
        },
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "f45ae81c-8201-46cd-ba7f-955b69070108",
      "name": "回复邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -96,
        32
      ],
      "webhookId": "4729862b-1009-44e9-a631-9b6651d34d0f",
      "parameters": {
        "message": "={{ $json.output }}",
        "options": {
          "appendAttribution": true,
          "replyToSenderOnly": false
        },
        "emailType": "text",
        "messageId": "={{ $('Get a message').item.json.id }}",
        "operation": "reply"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "PuAE61pOClI4CRxE",
          "name": "Gmail account"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "82f0e737-89c4-45cd-b18c-2d01f85218da",
  "connections": {
    "Get a message": {
      "main": [
        [
          {
            "node": "AI Categorizer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Get a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Categorizer": {
      "main": [
        [
          {
            "node": "Reply, Draft, or Nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Chat Draft": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Draft Email",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Chat Reply": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Email Reply",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Generate Draft Email": {
      "main": [
        [
          {
            "node": "Flag for Human Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Email Reply": {
      "main": [
        [
          {
            "node": "Reply Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Categorizer",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Reply, Draft, or Nothing": {
      "main": [
        [
          {
            "node": "Generate Email Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate Draft Email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 工单管理, 多模态 AI

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流