# Outlook - Multi-Mailbox Trigger

> 当多个 Microsoft Outlook 邮箱中的任意一个收到新邮件时触发。

Source: https://docs.sommatic.ai/zh/nodes/connectors.microsoft.outlook.trigger.multi/

- 标识: `connectors.microsoft.outlook.trigger.multi`
- 类别: 连接器
- 版本: 1.0.0
- 状态: 部分可用. 调度器不会启动该触发器：只能手动启动，且每次运行只触发一次，而不是每封邮件、每个邮箱各触发一次。
- 执行方式: async

当多个 Microsoft Outlook 邮箱中的任意一个收到新邮件时触发。

企业级多租户邮箱监听器。单个触发器节点并行监视一组邮箱，**每封新邮件触发一次工作流执行**，并在载荷中标明来源邮箱。非常适合共享收件箱架构（PQRS、客服、法务受理、人力资源），即多个职能邮箱需要汇入同一个分诊工作流的场景。

**工作原理：**
- 每个轮询周期，触发器并行检查所有已配置的邮箱（每个邮箱一次 Graph API 调用）。
- 每封新邮件都作为一次独立的触发：如果 3 个邮箱在同一周期各收到 1 封新邮件，工作流就执行 3 次。
- 来源邮箱以 `mailbox_email` 暴露在输出载荷中，供下游节点据此路由或打标签。
- `lastTimeChecked` 状态**按邮箱**独立跟踪（因此轮询较慢的邮箱不会阻塞其他邮箱）。
- 若邮件附件较多，会改用 `heavy_attachments` 端口而非 `out`，以便下游专门处理。

**何时优先选用它而不是单邮箱触发器：**
- 你有 2 个以上需要运行同一工作流的共享收件箱。
- 你不想维护 N 个功能完全相同的并行工作流（每个邮箱一个）。
- 你需要在一组邮箱之间保持一致的状态跟踪。

**何时不宜选用：**
- 每月邮件量超过 1 万封且需要亚秒级延迟：请改用 Graph webhooks + 队列（例如 Service Bus）。
- 各邮箱的下游逻辑差异明显：请使用各自独立的工作流。

## 配置

- `connection_id` (string, 必填): 用于访问 Microsoft Graph API 的凭据。应用注册必须对所有被监控邮箱拥有 Mail.Read 权限（Application）。接受 `oauth2`（access + refresh token）、`service-account`（tenant id + client id + client secret）或 `object`（高级 Graph 配置）类型的凭据。
- `mailbox_emails` (array<string>, 必填): 要监控的邮箱地址列表。每个邮箱地址都必须可由所配置的凭据访问。
- `folder` (string, 可选): 要监视新邮件的邮件文件夹（所有邮箱使用同一文件夹）。 默认值: `inbox`. 可选值: `inbox`, `sentitems`, `drafts`, `deleteditems`, `junkemail`, `archive`.
- `polling_interval` (number, 可选): 检查新邮件的频率。最少 60 秒。每个周期并行检查各邮箱。 默认值: `60`.
- `attachment_threshold` (number, 可选): 附件数量达到或超过此值时，邮件路由到 heavy_attachments 端口而不是 out。 默认值: `5`.
- `max_emails_per_cycle` (number, 可选): Graph API 的 $top 值。单个轮询周期内每个邮箱最多获取的新邮件数（其余等待下一周期）。 默认值: `50`.

配置中会显示通用执行设置，但该节点目前不执行重试（`retryOnFail`、`maxTries`）。所有节点均未实现 `continueOnFail`。

## 输出端口

- `out` (默认): 收到一封新邮件（低于附件阈值）。每个邮箱的每封邮件触发一次。
- `heavy_attachments`: 邮件附件数量达到或超过阈值。请路由到专门的附件处理节点。
- `empty`: 本轮轮询中所有被监控邮箱均未发现新邮件。
- `error`: 获取邮件失败或认证错误。

## 输出契约

- `id` (string, 可选): Graph 消息 ID。用于回复/转发/删除操作。
- `mailbox_email` (string, 可选): 收到这封邮件的邮箱。用于下游按邮箱路由。
- `subject` (string, 可选)
- `from` (string, 可选): 发件人邮箱地址。
- `to` (array, 可选): 收件人邮箱地址。
- `cc` (array, 可选)
- `receivedDateTime` (string, 可选)
- `body` (string, 可选): 邮件正文内容。
- `bodyContentType` (string, 可选)
- `bodyPreview` (string, 可选)
- `isRead` (boolean, 可选)
- `hasAttachments` (boolean, 可选)
- `attachmentCount` (number, 可选)
- `importance` (string, 可选)
- `conversationId` (string, 可选)
- `internetMessageId` (string, 可选)

## 在表达式中

后续节点可通过 `$("Outlook - Multi-Mailbox Trigger").item.json.<路径>` 读取此节点输出中的内容（请把 `Outlook - Multi-Mailbox Trigger` 换成你的节点标签）。**Editor** 标记工作流编辑器在 Previous Nodes 中提示的路径（输出契约）；**Worker** 标记 worker 实际通过 `out` 返回的路径，依据“端口”一节所示的输出。

- `$("Outlook - Multi-Mailbox Trigger").item.json.id` (string) = `"AAMkAGI2TG93AAA="`: Graph 消息 ID。用于回复/转发/删除操作。
- `$("Outlook - Multi-Mailbox Trigger").item.json.mailbox_email` (string) = `"billing@example.com"`: 收到这封邮件的邮箱。用于下游按邮箱路由。
- `$("Outlook - Multi-Mailbox Trigger").item.json.subject` (string) = `"Invoice request"`
- `$("Outlook - Multi-Mailbox Trigger").item.json.from` (string) = `"ana@example.com"`: 发件人邮箱地址。
- `$("Outlook - Multi-Mailbox Trigger").item.json.to` (array) = `[…] (1)`: 收件人邮箱地址。
- `$("Outlook - Multi-Mailbox Trigger").item.json.cc` (array) = `[…] (0)`
- `$("Outlook - Multi-Mailbox Trigger").item.json.receivedDateTime` (string) = `"2026-11-26T14:02:51Z"`
- `$("Outlook - Multi-Mailbox Trigger").item.json.body` (string) = `"<html><body><p>Please send the invoice.</p><…"`: 邮件正文内容。
- `$("Outlook - Multi-Mailbox Trigger").item.json.bodyContentType` (string) = `"html"`
- `$("Outlook - Multi-Mailbox Trigger").item.json.bodyPreview` (string) = `"Please send the invoice."`
- `$("Outlook - Multi-Mailbox Trigger").item.json.isRead` (boolean) = `false`
- `$("Outlook - Multi-Mailbox Trigger").item.json.hasAttachments` (boolean) = `false`
- `$("Outlook - Multi-Mailbox Trigger").item.json.attachmentCount` (number) **worker 不返回：读取结果为 undefined.**
- `$("Outlook - Multi-Mailbox Trigger").item.json.importance` (string) = `"normal"`
- `$("Outlook - Multi-Mailbox Trigger").item.json.conversationId` (string) = `"AAQkAGI2TG93CCC="`
- `$("Outlook - Multi-Mailbox Trigger").item.json.internetMessageId` (string) = `"<CAF1x2y3z@mail.example.com>"`
- `$("Outlook - Multi-Mailbox Trigger").item.json.messages` (array) = `[…] (1)` (编辑器不提示)
- `$("Outlook - Multi-Mailbox Trigger").item.json.count` (number) = `1` (编辑器不提示)
- `$("Outlook - Multi-Mailbox Trigger").item.json.hasNewEmails` (boolean) = `true` (编辑器不提示)
- `$("Outlook - Multi-Mailbox Trigger").item.json.lastTimeChecked` (string) = `"2026-11-26T14:03:00.120Z"` (编辑器不提示)


## 工作原理

以多个 Outlook 邮箱的新邮件启动工作流，各邮箱并行检查，并分别记录每个邮箱的上次检查时间。每次运行只输出一次：所有新邮件放在 `messages` 中，第一封邮件的字段复制到根级。

1. 触发来源：手动运行工作流。当前版本的后端调度器不会启动本节点（只调度 `cron.trigger` 和 `connectors.microsoft.outlook.trigger`）；只有输入中带有 `$scheduled: true` 时才会走计划运行分支。
2. 解析节点配置，必须提供 `connection_id`，且 `mailbox_emails`（数组或逗号分隔字符串）中至少有一个地址，然后获取 Graph 令牌。
3. 针对每个邮箱，查询 `folder` 中自其 `$trigger_state.perMailbox[<邮箱>].lastTimeChecked`（无记录时从当前时间）以来收到的邮件，按时间升序，最多 `max_emails_per_cycle` 封（默认 50），并为每封邮件标注 `mailbox_email`。
4. 计划分支：只检查一轮；查询失败的邮箱会被跳过，并保留其上次检查时间。手动运行：每 `polling_interval` 秒重复一轮并刷新令牌，直到任一邮箱有新邮件或满 30 分钟；任一邮箱失败都会导致本次运行失败。
5. 统计带附件邮件的附件数（最多 100 个），将第一封邮件的字段复制到根级，并选择 `empty`（无邮件）、`heavy_attachments`（第一封邮件附件数不少于 `attachment_threshold`）或 `out`。返回的 `meta.trigger_state.perMailbox` 会在运行结束后由后端保存。

## 在工作流中

### 节点

```json
{
  "node_id": "node-shared-inboxes",
  "label": "Shared inboxes",
  "operator_slug": "connectors.microsoft.outlook.trigger.multi",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "mailbox_emails": [
      "billing@example.com",
      "support@example.com"
    ],
    "folder": "inbox",
    "polling_interval": 60,
    "attachment_threshold": 5,
    "max_emails_per_cycle": 50
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "messages": [
      {
        "id": "AAMkAGI2TG93AAA=",
        "subject": "Invoice request",
        "from": "ana@example.com",
        "to": [
          "billing@example.com"
        ],
        "cc": [],
        "receivedDateTime": "2026-11-26T14:02:51Z",
        "body": "<html><body><p>Please send the invoice.</p></body></html>",
        "bodyContentType": "html",
        "bodyPreview": "Please send the invoice.",
        "isRead": false,
        "hasAttachments": false,
        "importance": "normal",
        "conversationId": "AAQkAGI2TG93CCC=",
        "internetMessageId": "<CAF1x2y3z@mail.example.com>",
        "mailbox_email": "billing@example.com"
      }
    ],
    "count": 1,
    "hasNewEmails": true,
    "lastTimeChecked": "2026-11-26T14:03:00.120Z",
    "id": "AAMkAGI2TG93AAA=",
    "subject": "Invoice request",
    "from": "ana@example.com",
    "to": [
      "billing@example.com"
    ],
    "cc": [],
    "receivedDateTime": "2026-11-26T14:02:51Z",
    "body": "<html><body><p>Please send the invoice.</p></body></html>",
    "bodyContentType": "html",
    "bodyPreview": "Please send the invoice.",
    "isRead": false,
    "hasAttachments": false,
    "importance": "normal",
    "conversationId": "AAQkAGI2TG93CCC=",
    "internetMessageId": "<CAF1x2y3z@mail.example.com>",
    "mailbox_email": "billing@example.com"
  },
  "port": "out",
  "meta": {
    "trigger_state": {
      "perMailbox": {
        "billing@example.com": {
          "lastTimeChecked": "2026-11-26T14:03:00.120Z"
        },
        "support@example.com": {
          "lastTimeChecked": "2026-11-26T14:03:00.120Z"
        }
      }
    }
  }
}
```

## 输出端口 (代码中的行为)

### `out`

至少一个邮箱有新邮件，且第一封邮件的附件数低于阈值。

```json
{
  "messages": [
    {
      "id": "AAMkAGI2TG93AAA=",
      "subject": "Invoice request",
      "from": "ana@example.com",
      "to": [
        "billing@example.com"
      ],
      "cc": [],
      "receivedDateTime": "2026-11-26T14:02:51Z",
      "body": "<html><body><p>Please send the invoice.</p></body></html>",
      "bodyContentType": "html",
      "bodyPreview": "Please send the invoice.",
      "isRead": false,
      "hasAttachments": false,
      "importance": "normal",
      "conversationId": "AAQkAGI2TG93CCC=",
      "internetMessageId": "<CAF1x2y3z@mail.example.com>",
      "mailbox_email": "billing@example.com"
    }
  ],
  "count": 1,
  "hasNewEmails": true,
  "lastTimeChecked": "2026-11-26T14:03:00.120Z",
  "id": "AAMkAGI2TG93AAA=",
  "subject": "Invoice request",
  "from": "ana@example.com",
  "to": [
    "billing@example.com"
  ],
  "cc": [],
  "receivedDateTime": "2026-11-26T14:02:51Z",
  "body": "<html><body><p>Please send the invoice.</p></body></html>",
  "bodyContentType": "html",
  "bodyPreview": "Please send the invoice.",
  "isRead": false,
  "hasAttachments": false,
  "importance": "normal",
  "conversationId": "AAQkAGI2TG93CCC=",
  "internetMessageId": "<CAF1x2y3z@mail.example.com>",
  "mailbox_email": "billing@example.com"
}
```

### `heavy_attachments`

第一封邮件附件数不少于 `attachment_threshold`。结构与 `out` 相同，邮件中带有 `attachmentCount`。

```json
{
  "messages": [
    {
      "id": "AAMkAGI2TG94AAA=",
      "subject": "Scanned documents",
      "from": "ana@example.com",
      "to": [
        "support@example.com"
      ],
      "cc": [],
      "receivedDateTime": "2026-11-26T14:03:40Z",
      "body": "<html><body><p>Attached.</p></body></html>",
      "bodyContentType": "html",
      "bodyPreview": "Attached.",
      "isRead": false,
      "hasAttachments": true,
      "importance": "normal",
      "conversationId": "AAQkAGI2TG94CCC=",
      "internetMessageId": "<CAF4u5v6w@mail.example.com>",
      "mailbox_email": "support@example.com",
      "attachmentCount": 7
    }
  ],
  "count": 1,
  "hasNewEmails": true,
  "lastTimeChecked": "2026-11-26T14:04:00.087Z",
  "id": "AAMkAGI2TG94AAA=",
  "subject": "Scanned documents",
  "from": "ana@example.com",
  "to": [
    "support@example.com"
  ],
  "cc": [],
  "receivedDateTime": "2026-11-26T14:03:40Z",
  "body": "<html><body><p>Attached.</p></body></html>",
  "bodyContentType": "html",
  "bodyPreview": "Attached.",
  "isRead": false,
  "hasAttachments": true,
  "importance": "normal",
  "conversationId": "AAQkAGI2TG94CCC=",
  "internetMessageId": "<CAF4u5v6w@mail.example.com>",
  "mailbox_email": "support@example.com",
  "attachmentCount": 7
}
```

### `empty`

所有邮箱都没有新邮件（计划分支），或手动运行等待 30 分钟仍无邮件（此时带有 `timedOut: true` 和 `polledForMs`）。

```json
{
  "messages": [],
  "count": 0,
  "hasNewEmails": false,
  "lastTimeChecked": "2026-11-26T14:33:00.502Z",
  "timedOut": true,
  "polledForMs": 1800381
}
```

### `error`

校验失败（输出为信封 `{ ok, errors, port }`），或手动运行时某个邮箱查询失败（输出为 `{ error }`）。

```json
{
  "ok": false,
  "errors": [
    "At least one mailbox email is required"
  ],
  "port": "error"
}
```

## 代码中的行为

- `mailbox_emails`: 接受数组或逗号分隔字符串。凭据必须具备应用权限 `Mail.Read`，能读取每个邮箱。
- `attachment_threshold`: 即使收到多封邮件，也只针对第一封邮件评估。
- `polling_interval`: 手动运行时两轮检查之间的等待时间。不强制 60 秒最小值，后端调度器也不会为本节点使用该值。

## 错误

| 消息 | 端口 | 原因与处理 |
| --- | --- | --- |
| `Microsoft 365 credential is required` | `error` | `connection_id` 为空。 |
| `At least one mailbox email is required` | `error` | `mailbox_emails` 为空或不包含有效字符串。 |
| `Failed to resolve Microsoft 365 access token` | `error` | 凭据无法解析或令牌申请失败。 |
| `Poll failed: <message>` | `error` | 手动运行：某个邮箱的查询失败（例如缺少该邮箱的 `Mail.Read` 权限时返回 403）。 |

## 说明与限制

- 定义中称每个邮箱的每封邮件触发一次，但代码每次运行只触发一次。找到的所有邮件都在 `messages` 中，只有第一封复制到根级，且所有邮箱的上次检查时间都会前移，因此请遍历 `messages`（例如使用 `flow.split`），不要依赖根级字段。
- 与单邮箱触发器不同，手动运行时若存在已保存的各邮箱上次检查时间，会从该时间开始检查，因此也会返回自上次运行以来收到的邮件。
- 使用示例数据时，引擎会跳过本节点并经 `out` 输出示例输入。手动运行最长会阻塞 30 分钟。


## 契约（JSON Schema）

### All (`*.definition.js`)

```json
{
  "slug": "connectors.microsoft.outlook.trigger.multi",
  "name": "Outlook - Multi-Mailbox Trigger",
  "category": "integrations",
  "version": "1.0.0",
  "description": "Triggers when a new email arrives in ANY of multiple Microsoft Outlook mailboxes.\n\n  Enterprise-grade multi-tenant mailbox listener. A single trigger node watches a list of mailboxes in parallel and fires **one workflow execution per new email**, with the originating mailbox identified in the payload. Ideal for shared inbox architectures (PQRS, support, legal intake, HR) where several functional mailboxes must feed the same triage workflow.\n\n  **How it works:**\n  - On each polling cycle, the trigger checks ALL configured mailboxes in parallel (one Graph API call per mailbox).\n  - Every new email found is emitted as an independent trigger fire — if 3 mailboxes each receive 1 new email in the same cycle, the workflow executes 3 times.\n  - The originating mailbox is exposed as `mailbox_email` in the output payload so downstream nodes can route or tag accordingly.\n  - `lastTimeChecked` state is tracked **per mailbox** independently (so a slow-polling mailbox does not block others).\n  - If an email has many attachments, the `heavy_attachments` port is used instead of `out` for dedicated downstream processing.\n\n  **When to prefer this over the single-mailbox trigger:**\n  - You have 2+ shared inboxes that should run the same workflow.\n  - You want to avoid maintaining N parallel workflows (one per mailbox) that all do the same thing.\n  - You need consistent state tracking across a mailbox cluster.\n\n  **When NOT to prefer this:**\n  - You have >10K emails/month and need sub-second latency — use Graph webhooks + a queue (e.g. Service Bus) instead.\n  - Each mailbox has materially different downstream logic — use separate workflows.",
  "capabilities": [
    "email",
    "microsoft",
    "outlook",
    "trigger",
    "multi-mailbox",
    "shared-inbox"
  ],
  "group": [
    {
      "key": "microsoft",
      "name": "Microsoft",
      "icon_url": "/icons/integrations/microsoft/microsoft.svg"
    },
    {
      "key": "microsoft365",
      "name": "Microsoft 365",
      "icon_url": "/icons/integrations/microsoft/microsoft365.svg"
    }
  ],
  "icon_url": "/icons/integrations/microsoft/outlook.svg",
  "config_schema": {
    "type": "object",
    "properties": {
      "connection_id": {
        "type": "string",
        "title": "Microsoft 365 Credential",
        "description": "Credential for Microsoft Graph API access. The app registration must have Mail.Read permission (Application) on all monitored mailboxes. Accepts credentials of type `oauth2` (access + refresh token), `service-account` (tenant id + client id + client secret), or `object` (advanced Graph config).",
        "ui_widget": "connection_picker",
        "ui_options": {
          "credential_types": [
            "oauth2",
            "service-account",
            "object"
          ],
          "types": [
            "outlook",
            "microsoft365",
            "oauth2"
          ]
        }
      },
      "mailbox_emails": {
        "type": "array",
        "title": "Mailbox Emails",
        "description": "List of mailbox email addresses to monitor. Each email address must be accessible by the configured credential.",
        "items": {
          "type": "string",
          "format": "expression"
        }
      },
      "folder": {
        "type": "string",
        "title": "Folder",
        "enum": [
          "inbox",
          "sentitems",
          "drafts",
          "deleteditems",
          "junkemail",
          "archive"
        ],
        "default": "inbox",
        "description": "The mail folder to watch for new messages (same folder applies to all mailboxes)."
      },
      "polling_interval": {
        "type": "number",
        "title": "Polling Interval (seconds)",
        "default": 60,
        "description": "How often to check for new emails. Minimum 60 seconds. Each mailbox is checked in parallel per cycle."
      },
      "attachment_threshold": {
        "type": "number",
        "title": "Heavy Attachments Threshold",
        "default": 5,
        "description": "Number of attachments at or above which the email routes to the heavy_attachments port instead of out."
      },
      "max_emails_per_cycle": {
        "type": "number",
        "title": "Max Emails Per Mailbox Per Cycle",
        "default": 50,
        "description": "Graph API $top value. Cap on how many new emails per mailbox are fetched in a single polling cycle (rest wait for next cycle)."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    },
    "required": [
      "connection_id",
      "mailbox_emails"
    ]
  },
  "input_contract_schema": null,
  "output_contract_schema": {
    "type": "object",
    "description": "The incoming email data, with the originating mailbox surfaced for routing.",
    "properties": {
      "id": {
        "type": "string",
        "description": "The Graph message ID. Use this for reply/forward/delete operations."
      },
      "mailbox_email": {
        "type": "string",
        "description": "The mailbox this email was received in. Use this for per-mailbox routing downstream."
      },
      "subject": {
        "type": "string"
      },
      "from": {
        "type": "string",
        "description": "Sender email address."
      },
      "to": {
        "type": "array",
        "description": "Recipient email addresses."
      },
      "cc": {
        "type": "array"
      },
      "receivedDateTime": {
        "type": "string",
        "format": "date-time"
      },
      "body": {
        "type": "string",
        "description": "Email body content."
      },
      "bodyContentType": {
        "type": "string"
      },
      "bodyPreview": {
        "type": "string"
      },
      "isRead": {
        "type": "boolean"
      },
      "hasAttachments": {
        "type": "boolean"
      },
      "attachmentCount": {
        "type": "number"
      },
      "importance": {
        "type": "string"
      },
      "conversationId": {
        "type": "string"
      },
      "internetMessageId": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "New Email",
      "is_default": true,
      "description": "A new email was received (below attachment threshold). Fires once per email per mailbox."
    },
    {
      "port_id": "heavy_attachments",
      "label": "Heavy Attachments",
      "description": "Email has attachments at or above the threshold. Route to a dedicated attachment processing node."
    },
    {
      "port_id": "empty",
      "label": "No New Emails",
      "description": "No new emails found in any monitored mailbox in this polling cycle."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Failed to fetch emails or authentication error."
    }
  ],
  "execution_mode": "async",
  "tags": [
    "email",
    "microsoft",
    "outlook",
    "trigger",
    "multi-mailbox",
    "shared-inbox",
    "premium"
  ],
  "is_stateful": true,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "connection_id": {
      "type": "string",
      "title": "Microsoft 365 Credential",
      "description": "Credential for Microsoft Graph API access. The app registration must have Mail.Read permission (Application) on all monitored mailboxes. Accepts credentials of type `oauth2` (access + refresh token), `service-account` (tenant id + client id + client secret), or `object` (advanced Graph config).",
      "ui_widget": "connection_picker",
      "ui_options": {
        "credential_types": [
          "oauth2",
          "service-account",
          "object"
        ],
        "types": [
          "outlook",
          "microsoft365",
          "oauth2"
        ]
      }
    },
    "mailbox_emails": {
      "type": "array",
      "title": "Mailbox Emails",
      "description": "List of mailbox email addresses to monitor. Each email address must be accessible by the configured credential.",
      "items": {
        "type": "string",
        "format": "expression"
      }
    },
    "folder": {
      "type": "string",
      "title": "Folder",
      "enum": [
        "inbox",
        "sentitems",
        "drafts",
        "deleteditems",
        "junkemail",
        "archive"
      ],
      "default": "inbox",
      "description": "The mail folder to watch for new messages (same folder applies to all mailboxes)."
    },
    "polling_interval": {
      "type": "number",
      "title": "Polling Interval (seconds)",
      "default": 60,
      "description": "How often to check for new emails. Minimum 60 seconds. Each mailbox is checked in parallel per cycle."
    },
    "attachment_threshold": {
      "type": "number",
      "title": "Heavy Attachments Threshold",
      "default": 5,
      "description": "Number of attachments at or above which the email routes to the heavy_attachments port instead of out."
    },
    "max_emails_per_cycle": {
      "type": "number",
      "title": "Max Emails Per Mailbox Per Cycle",
      "default": 50,
      "description": "Graph API $top value. Cap on how many new emails per mailbox are fetched in a single polling cycle (rest wait for next cycle)."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  },
  "required": [
    "connection_id",
    "mailbox_emails"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "The incoming email data, with the originating mailbox surfaced for routing.",
  "properties": {
    "id": {
      "type": "string",
      "description": "The Graph message ID. Use this for reply/forward/delete operations."
    },
    "mailbox_email": {
      "type": "string",
      "description": "The mailbox this email was received in. Use this for per-mailbox routing downstream."
    },
    "subject": {
      "type": "string"
    },
    "from": {
      "type": "string",
      "description": "Sender email address."
    },
    "to": {
      "type": "array",
      "description": "Recipient email addresses."
    },
    "cc": {
      "type": "array"
    },
    "receivedDateTime": {
      "type": "string",
      "format": "date-time"
    },
    "body": {
      "type": "string",
      "description": "Email body content."
    },
    "bodyContentType": {
      "type": "string"
    },
    "bodyPreview": {
      "type": "string"
    },
    "isRead": {
      "type": "boolean"
    },
    "hasAttachments": {
      "type": "boolean"
    },
    "attachmentCount": {
      "type": "number"
    },
    "importance": {
      "type": "string"
    },
    "conversationId": {
      "type": "string"
    },
    "internetMessageId": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "New Email",
    "is_default": true,
    "description": "A new email was received (below attachment threshold). Fires once per email per mailbox."
  },
  {
    "port_id": "heavy_attachments",
    "label": "Heavy Attachments",
    "description": "Email has attachments at or above the threshold. Route to a dedicated attachment processing node."
  },
  {
    "port_id": "empty",
    "label": "No New Emails",
    "description": "No new emails found in any monitored mailbox in this polling cycle."
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Failed to fetch emails or authentication error."
  }
]
```
