8
n8n 中文网amn8n.com

使用AI代理自动分类Outlook邮件

中级

这是一个Ticket Management, AI Summarization领域的自动化工作流,包含 9 个节点。主要使用 Code, Markdown, Agent, MicrosoftOutlookTool, MicrosoftOutlookTrigger 等节点。 使用GPT-4.1代理自动整理Outlook收件箱

前置要求
  • 无特殊前置要求,导入即可使用
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "2eEiaDecIH2A1L5B",
  "meta": {
    "instanceId": "57ebb56a6cec4a647aac549d1f247468258466306bf889b902942d504f76d0ec",
    "templateId": "2454",
    "templateCredsSetupCompleted": true
  },
  "name": "使用 AI 代理自动分类 Outlook 邮件",
  "tags": [
    {
      "id": "CbUjmxKVzwUyY7rS",
      "name": "metamation",
      "createdAt": "2025-02-27T02:44:26.211Z",
      "updatedAt": "2025-02-27T02:44:26.211Z"
    }
  ],
  "nodes": [
    {
      "id": "3269968d-0373-45a0-9e29-10c4859b6197",
      "name": "Microsoft Outlook 触发器",
      "type": "n8n-nodes-base.microsoftOutlookTrigger",
      "position": [
        320,
        272
      ],
      "parameters": {
        "fields": [
          "from",
          "subject",
          "isRead",
          "body"
        ],
        "output": "fields",
        "filters": {
          "foldersToInclude": [
            "AAMkAGRiZDlmMzhhLTRjOTctNGYxZC1iZDNjLTRhNTFkZGMzZTQ5YwAuAAAAAACdE2dovEwhS5uGZMOqP8rcAQCwdsIutyDWQrW17vFEit2HAAAAAAEMAAA="
          ]
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "4KC5nBToT6YWStpV",
          "name": "Microsoft Outlook - Alex METAMATION"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3519328e-d6fa-482d-b2eb-8283d2e06bd7",
      "name": "AI 代理 - 确定类别",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        960,
        272
      ],
      "parameters": {
        "text": "=Your goal is to keep the user's Inbox clean, containing ONLY actionable client communication or new inquiries. Categorise the email below by selecting the most appropriate folder ID from the list provided.\n\nEmail Subject: {{ $('Microsoft Outlook Trigger').item.json.subject }}\nSenders Email: {{ $('Microsoft Outlook Trigger').item.json.from.emailAddress.address }}\nSenders Name: {{ $('Microsoft Outlook Trigger').item.json.from.emailAddress.name }}\nEmail Body: {{ $json.sanitizedBody }}\nEmail ID: {{ $('Microsoft Outlook Trigger').item.json.id }}\n\n**Instructions:**\n1. First, determine if this email requires direct user action/reply (e.g., a client message, a new inquiry from a person). If YES, choose the ID for the 'Action' folder.\n2. If NO, determine the best category folder from the list provided (e.g., Junk, Receipt, SaaS, Community, Business, Other) and choose its ID.\n3. If none of the standard folders fit well, choose the ID for the 'Other' folder.\n4. Analyze sender, subject, and body.\n5. Emails that contain an ongoing conversation should not be moved.\n6. Use all tools to retrieve folders, contacts, and the ability to move messages, using ID's. \n7. Only ID of folders are recognized by outlook tools whening moving messages. \n8. Make sure to use the think tool. \n9. If a message is not moved, very briefly explain why. \n\nMessages from saved contacts should not be moved. \n\nIf the from field is an actual human, e.g. not a support@x.com, info@x.com, then do not use the move tool and simply output why it was not moved. You can also interpret this as if there is a persons name in the email.\ne.g. john@metamation.net.",
        "options": {
          "systemMessage": "You are an expert assistant for Alex helping manage his Outlook Inbox. The PRIMARY GOAL is to move all non-essential emails OUT of the Inbox."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.6
    },
    {
      "id": "074a81c3-de13-455e-98c4-6b69f69830d0",
      "name": "移动消息",
      "type": "n8n-nodes-base.microsoftOutlookTool",
      "position": [
        992,
        496
      ],
      "webhookId": "d79de56d-8e0f-47a0-b90a-0d5984cefb8d",
      "parameters": {
        "folderId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Parent_Folder', `ID of the folder to move the message to`, 'string') }}"
        },
        "messageId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Message', `ID of the email`, 'string') }}"
        },
        "operation": "move"
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "4KC5nBToT6YWStpV",
          "name": "Microsoft Outlook - Alex METAMATION"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "a18369cf-6ef2-4f90-ab20-c2d09350a06a",
      "name": "获取文件夹",
      "type": "n8n-nodes-base.microsoftOutlookTool",
      "position": [
        1120,
        496
      ],
      "webhookId": "3ca45b6d-1716-4642-812d-798a18565717",
      "parameters": {
        "filters": {},
        "options": {},
        "resource": "folder",
        "operation": "getAll",
        "returnAll": true,
        "descriptionType": "manual",
        "toolDescription": "All folders available to move messages to. "
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "4KC5nBToT6YWStpV",
          "name": "Microsoft Outlook - Alex METAMATION"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "90c2c14d-5189-4793-9615-b83772185715",
      "name": "OpenRouter聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        864,
        496
      ],
      "parameters": {
        "model": "openai/gpt-4.1",
        "options": {}
      },
      "credentials": {
        "openRouterApi": {
          "id": "epNOLCfZGhs7dyQh",
          "name": "OpenRouter METAMATION"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "137a6971-7823-4929-9034-2081774793af",
      "name": "获取联系人",
      "type": "n8n-nodes-base.microsoftOutlookTool",
      "position": [
        1248,
        496
      ],
      "webhookId": "b17b3911-ff01-423c-80f6-f5419e60925b",
      "parameters": {
        "filters": {},
        "resource": "contact",
        "returnAll": true,
        "descriptionType": "manual",
        "toolDescription": "All saved contacts."
      },
      "credentials": {
        "microsoftOutlookOAuth2Api": {
          "id": "4KC5nBToT6YWStpV",
          "name": "Microsoft Outlook - Alex METAMATION"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "53a13b8f-1f87-498e-a386-56b0d13ee122",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -944,
        -176
      ],
      "parameters": {
        "width": 1200,
        "height": 1136,
        "content": "# 在 n8n 中使用 AI 自动分类 Outlook 邮件"
      },
      "typeVersion": 1
    },
    {
      "id": "b9cf3998-4e0f-4eb3-b7d5-66f0095afdbc",
      "name": "Markdown",
      "type": "n8n-nodes-base.markdown",
      "position": [
        544,
        272
      ],
      "parameters": {
        "html": "={{ $json.body.content }}",
        "options": {},
        "destinationKey": "Email Body Markdown"
      },
      "typeVersion": 1
    },
    {
      "id": "1c6e14b7-9d17-4780-8e84-e5f047672366",
      "name": "清理邮件正文",
      "type": "n8n-nodes-base.code",
      "position": [
        768,
        272
      ],
      "parameters": {
        "jsCode": "// Get the markdown content from the previous node\nconst markdownContent = $input.item.json[\"Email Body Markdown\"];\n\nlet plainText = markdownContent;\n\n// 1. Remove Markdown images completely\nplainText = plainText.replace(/!\\[.*?\\]\\(.*?\\)/g, '');\n\n// 2. Simplify Markdown links - keep text, replace URL with '[link]'\nplainText = plainText.replace(/\\[(.*?)\\]\\(.*?\\)/g, '$1 [link]');\n// --- OR Remove [link] placeholder entirely if not needed ---\n// plainText = plainText.replace(/\\[(.*?)\\]\\(.*?\\)/g, '$1');\n\n// 3. Remove any remaining HTML-like tags\nplainText = plainText.replace(/<[^>]*>/g, '');\n\n// 4. Remove Markdown table separators and leading/trailing pipes from lines\nplainText = plainText.replace(/^\\||\\|$/gm, ''); // Remove leading/trailing pipes per line\nplainText = plainText.replace(/^\\s*[-|:]+\\s*$/gm, ''); // Remove lines that are just separators\n\n// 5. Normalize and reduce whitespace (run this AFTER other removals)\nplainText = plainText.replace(/(\\s*\\r?\\n\\s*){2,}/g, '\\n\\n'); // Collapse multiple blank lines\nplainText = plainText.split('\\n').map(line => line.trim()).filter(line => line.length > 0).join('\\n'); // Trim lines, remove empty lines\nplainText = plainText.trim(); // Trim whole string\n\n// 6. Truncate (Keep this step last)\nconst MAX_CHARS = 4000; // Or your desired limit\nif (plainText.length > MAX_CHARS) {\n  plainText = plainText.substring(0, MAX_CHARS) + \"... (truncated)\";\n}\n\n// Return the more thoroughly sanitized text\nreturn { sanitizedBody: plainText };"
      },
      "typeVersion": 2
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {},
  "versionId": "63068993-f77e-450a-9831-e227bb2637ae",
  "connections": {
    "Markdown": {
      "main": [
        [
          {
            "node": "Sanitize Email Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Folders": {
      "ai_tool": [
        [
          {
            "node": "AI Agent - Determine Category",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get Contacts": {
      "ai_tool": [
        [
          {
            "node": "AI Agent - Determine Category",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Move Message": {
      "ai_tool": [
        [
          {
            "node": "AI Agent - Determine Category",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Sanitize Email Body": {
      "main": [
        [
          {
            "node": "AI Agent - Determine Category",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent - Determine Category",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Microsoft Outlook Trigger": {
      "main": [
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent - Determine Category": {
      "main": [
        []
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
AlexAutomates

AlexAutomates

@automatoralex

I’m Alex De Gracia, founder of METAMATION. I help small and midsize businesses save time and grow by building smart, automated digital ecosystems. With a hands-on, practical approach, I design custom web solutions and integrations that turn manual work into seamless workflows. My goal is to make modern technology easy and valuable for every business I partner with.

外部链接
在 n8n.io 查看

分享此工作流