# Outlook - New Email

> Triggers when a new email arrives in a Microsoft Outlook mailbox.

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

- Slug: `connectors.microsoft.outlook.trigger`
- Family: Connectors
- Version: 1.0.0
- Status: Available
- Execution: async

Triggers when a new email arrives in a Microsoft Outlook mailbox.

Listens for incoming emails via Microsoft Graph API subscriptions. When a new email is received, the workflow is triggered with the full email data (id, subject, from, body, attachments info).

**How it works:**
- When the workflow starts, a Graph API subscription is created for the configured mailbox.
- Microsoft notifies Sommatic AI when a new email arrives.
- The trigger fetches the full email and passes it to the next node.

**Use Cases:**
- Auto-reply to incoming support emails.
- Process email attachments (OCR, classification).
- Route emails to different workflows based on sender or subject.

## Configuration

- `connection_id` (string, required): Credential for Microsoft Graph API access. Accepts credentials of type `oauth2` (access + refresh token), `service-account` (tenant id + client id + client secret), or `object` (advanced Graph config).
- `mailbox_email` (string, required, accepts expressions): Email address of the mailbox to monitor for new emails.
- `folder` (string, optional): The mail folder to watch for new messages. Default: `inbox`. Allowed values: `inbox`, `sentitems`, `drafts`, `deleteditems`, `junkemail`, `archive`.
- `polling_interval` (number, optional): How often to check for new emails. Minimum 60 seconds. Default: `60`.
- `attachment_threshold` (number, optional): Number of attachments at or above which the email routes to the heavy_attachments port. Useful for routing to a dedicated attachment processing node. Default: `5`.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `out` (default): A new email was received (below attachment threshold).
- `heavy_attachments`: Email has attachments at or above the threshold. Route to a dedicated attachment processing node.
- `empty`: No new emails found in this polling cycle.
- `error`: Failed to fetch email or subscription error.

## Output contract

- `id` (string, optional): The message ID. Use this for reply/forward/delete operations.
- `subject` (string, optional)
- `from` (string, optional): Sender email address.
- `to` (array, optional): Recipient email addresses.
- `receivedDateTime` (string, optional)
- `body` (string, optional): Email body content.
- `bodyPreview` (string, optional)
- `isRead` (boolean, optional)
- `hasAttachments` (boolean, optional)
- `attachmentCount` (number, optional): Number of attachments.
- `importance` (string, optional)

## In expressions

What a later node can read from this node's output with `$("Outlook - New Email").item.json.<path>` (write your node's label instead of `Outlook - New Email`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Outlook - New Email").item.json.id` (string) = `"AAMkAGI2TG93AAA="`: The message ID. Use this for reply/forward/delete operations.
- `$("Outlook - New Email").item.json.subject` (string) = `"Order 123 question"`
- `$("Outlook - New Email").item.json.from` (string) = `"ana@example.com"`: Sender email address.
- `$("Outlook - New Email").item.json.to` (array) = `[…] (1)`: Recipient email addresses.
- `$("Outlook - New Email").item.json.receivedDateTime` (string) = `"2026-11-26T14:02:51Z"`
- `$("Outlook - New Email").item.json.body` (string) = `"<html><body><p>Hello, where is my order?</p>…"`: Email body content.
- `$("Outlook - New Email").item.json.bodyPreview` (string) = `"Hello, where is my order?"`
- `$("Outlook - New Email").item.json.isRead` (boolean) = `false`
- `$("Outlook - New Email").item.json.hasAttachments` (boolean) = `true`
- `$("Outlook - New Email").item.json.attachmentCount` (number) = `1`: Number of attachments.
- `$("Outlook - New Email").item.json.importance` (string) = `"normal"`
- `$("Outlook - New Email").item.json.messages` (array) = `[…] (1)` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.count` (number) = `1` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.hasNewEmails` (boolean) = `true` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.lastTimeChecked` (string) = `"2026-11-26T14:03:00.120Z"` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.previousCheckAt` (string) = `"2026-11-26T14:02:00.004Z"` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.cc` (array) = `[…] (0)` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.bodyContentType` (string) = `"html"` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.conversationId` (string) = `"AAQkAGI2TG93CCC="` (Not suggested by the editor)
- `$("Outlook - New Email").item.json.internetMessageId` (string) = `"<CAF1x2y3z@mail.example.com>"` (Not suggested by the editor)


## How it works

Starts a workflow with the new messages of one Outlook mailbox folder. On a schedule it checks once per polling interval since the last check; in a manual run it waits until mail arrives (up to 30 minutes).

1. What starts it: the backend scheduler checks every 10 seconds the active workflows that have a published version and contain this node, and starts the published version when `polling_interval` seconds (default 60) have passed since its last start, with the input `{ $scheduled: true }` plus the stored `$trigger_state`.
2. Resolves the node config, requires `connection_id` and `mailbox_email`, gets a Graph token and always targets `/users/<mailbox_email>`.
3. If the incoming item has `resource` (a Graph change notification), it fetches that message and returns it on `out`.
4. Scheduled run: one query for messages of `folder` received from `$trigger_state.lastTimeChecked` up to now, oldest first, at most 50. Manual run: the same query every `polling_interval` seconds from the moment the run started, refreshing the token each cycle, until a message arrives or 30 minutes pass.
5. Counts the attachments (up to 100) of each message that has them, and when exactly one message arrived it copies that message's fields to the root of the output.
6. Chooses `empty` when no message arrived, `heavy_attachments` when exactly one arrived and its `attachmentCount` is at least `attachment_threshold`, and `out` otherwise. It returns `meta.trigger_state.lastTimeChecked`, which the backend merges into the workflow's stored trigger state after the run.

## In a workflow

### Node

```json
{
  "node_id": "node-support-inbox",
  "label": "Support inbox",
  "operator_slug": "connectors.microsoft.outlook.trigger",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "mailbox_email": "support@example.com",
    "folder": "inbox",
    "polling_interval": 60,
    "attachment_threshold": 5
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "messages": [
      {
        "id": "AAMkAGI2TG93AAA=",
        "subject": "Order 123 question",
        "from": "ana@example.com",
        "to": [
          "support@example.com"
        ],
        "cc": [],
        "receivedDateTime": "2026-11-26T14:02:51Z",
        "body": "<html><body><p>Hello, where is my order?</p></body></html>",
        "bodyContentType": "html",
        "bodyPreview": "Hello, where is my order?",
        "isRead": false,
        "hasAttachments": true,
        "importance": "normal",
        "conversationId": "AAQkAGI2TG93CCC=",
        "internetMessageId": "<CAF1x2y3z@mail.example.com>",
        "attachmentCount": 1
      }
    ],
    "count": 1,
    "hasNewEmails": true,
    "lastTimeChecked": "2026-11-26T14:03:00.120Z",
    "previousCheckAt": "2026-11-26T14:02:00.004Z",
    "id": "AAMkAGI2TG93AAA=",
    "subject": "Order 123 question",
    "from": "ana@example.com",
    "to": [
      "support@example.com"
    ],
    "cc": [],
    "receivedDateTime": "2026-11-26T14:02:51Z",
    "body": "<html><body><p>Hello, where is my order?</p></body></html>",
    "bodyContentType": "html",
    "bodyPreview": "Hello, where is my order?",
    "isRead": false,
    "hasAttachments": true,
    "importance": "normal",
    "conversationId": "AAQkAGI2TG93CCC=",
    "internetMessageId": "<CAF1x2y3z@mail.example.com>",
    "attachmentCount": 1
  },
  "port": "out",
  "meta": {
    "trigger_state": {
      "lastTimeChecked": "2026-11-26T14:03:00.120Z"
    }
  }
}
```

## Output ports (behaviour in the code)

### `out`

New messages arrived (and not the heavy single-message case). The root fields of the email are present only when exactly one message arrived.

```json
{
  "messages": [
    {
      "id": "AAMkAGI2TG93AAA=",
      "subject": "Order 123 question",
      "from": "ana@example.com",
      "to": [
        "support@example.com"
      ],
      "cc": [],
      "receivedDateTime": "2026-11-26T14:02:51Z",
      "body": "<html><body><p>Hello, where is my order?</p></body></html>",
      "bodyContentType": "html",
      "bodyPreview": "Hello, where is my order?",
      "isRead": false,
      "hasAttachments": true,
      "importance": "normal",
      "conversationId": "AAQkAGI2TG93CCC=",
      "internetMessageId": "<CAF1x2y3z@mail.example.com>",
      "attachmentCount": 1
    }
  ],
  "count": 1,
  "hasNewEmails": true,
  "lastTimeChecked": "2026-11-26T14:03:00.120Z",
  "previousCheckAt": "2026-11-26T14:02:00.004Z",
  "id": "AAMkAGI2TG93AAA=",
  "subject": "Order 123 question",
  "from": "ana@example.com",
  "to": [
    "support@example.com"
  ],
  "cc": [],
  "receivedDateTime": "2026-11-26T14:02:51Z",
  "body": "<html><body><p>Hello, where is my order?</p></body></html>",
  "bodyContentType": "html",
  "bodyPreview": "Hello, where is my order?",
  "isRead": false,
  "hasAttachments": true,
  "importance": "normal",
  "conversationId": "AAQkAGI2TG93CCC=",
  "internetMessageId": "<CAF1x2y3z@mail.example.com>",
  "attachmentCount": 1
}
```

### `heavy_attachments`

Exactly one message arrived and it has `attachment_threshold` attachments or more. The output has the same shape as `out`.

```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>",
      "attachmentCount": 7
    }
  ],
  "count": 1,
  "hasNewEmails": true,
  "lastTimeChecked": "2026-11-26T14:04:00.087Z",
  "previousCheckAt": "2026-11-26T14:03:00.120Z",
  "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>",
  "attachmentCount": 7
}
```

### `empty`

No new message in this check. When a manual run waits 30 minutes without mail, the output also has `timedOut: true` and `polledForMs`.

```json
{
  "messages": [],
  "count": 0,
  "hasNewEmails": false,
  "lastTimeChecked": "2026-11-26T14:05:00.031Z",
  "previousCheckAt": "2026-11-26T14:04:00.087Z"
}
```

### `error`

A validation failed (the output is the envelope `{ ok, errors, port }`) or the Graph query failed (the output is `{ error }`).

```json
{
  "error": "Request failed with status code 403"
}
```

## Behaviour in the code

- `polling_interval`: The 60-second minimum is not enforced. The scheduler reads it from the workflow draft, and in manual runs it is the wait between checks.
- `attachment_threshold`: Only evaluated when exactly one message arrived; with several messages the port is always `out`.
- `folder`: A Graph well-known folder name, used as is in the request path.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Microsoft 365 credential is required` | `error` | `connection_id` is empty. `Mailbox email is required` is the same check for `mailbox_email`. |
| `Failed to resolve Microsoft 365 access token` | `error` | The credential could not be resolved or the token request failed. |
| `Poll failed: <message>` | `error` | The message query failed, for example 403 when the app lacks `Mail.Read` on the mailbox or 404 for an unknown mailbox. |
| `Failed to fetch email from resource: <message>` | `error` | The message referenced by a change notification could not be read. |

## Notes and limits

- Test vs production: only the published version is started by the scheduler, so a draft never polls on its own. Running the workflow manually starts the blocking polling loop instead; with sample data the engine skips this node and passes the sample input on `out`.
- The first scheduled run (no stored state) checks the window from now to now, so it finds nothing; mail is picked up from the next cycle on.
- At most 50 messages are read per check and `lastTimeChecked` then moves to now, so messages beyond the first 50 in one interval are not picked up. When several messages arrive, process `messages` (for example with `flow.split`).
- The mailbox is addressed as `/users/<mailbox_email>`, so the credential needs application permission `Mail.Read` (client credentials). The full message `body` is included in the output.


## Contracts (JSON Schema)

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

```json
{
  "slug": "connectors.microsoft.outlook.trigger",
  "name": "Outlook - New Email",
  "category": "integrations",
  "version": "1.0.0",
  "description": "Triggers when a new email arrives in a Microsoft Outlook mailbox.\n\n  Listens for incoming emails via Microsoft Graph API subscriptions. When a new email is received, the workflow is triggered with the full email data (id, subject, from, body, attachments info).\n\n  **How it works:**\n  - When the workflow starts, a Graph API subscription is created for the configured mailbox.\n  - Microsoft notifies Sommatic AI when a new email arrives.\n  - The trigger fetches the full email and passes it to the next node.\n\n  **Use Cases:**\n  - Auto-reply to incoming support emails.\n  - Process email attachments (OCR, classification).\n  - Route emails to different workflows based on sender or subject.",
  "capabilities": [
    "email",
    "microsoft",
    "outlook",
    "trigger",
    "webhook"
  ],
  "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. 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_email": {
        "type": "string",
        "title": "Mailbox Email",
        "description": "Email address of the mailbox to monitor for new emails.",
        "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."
      },
      "polling_interval": {
        "type": "number",
        "title": "Polling Interval (seconds)",
        "default": 60,
        "description": "How often to check for new emails. Minimum 60 seconds."
      },
      "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. Useful for routing to a dedicated attachment processing node."
      },
      "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_email"
    ]
  },
  "input_contract_schema": null,
  "output_contract_schema": {
    "type": "object",
    "description": "The incoming email data from Microsoft Graph API.",
    "properties": {
      "id": {
        "type": "string",
        "description": "The message ID. Use this for reply/forward/delete operations."
      },
      "subject": {
        "type": "string"
      },
      "from": {
        "type": "string",
        "description": "Sender email address."
      },
      "to": {
        "type": "array",
        "description": "Recipient email addresses."
      },
      "receivedDateTime": {
        "type": "string",
        "format": "date-time"
      },
      "body": {
        "type": "string",
        "description": "Email body content."
      },
      "bodyPreview": {
        "type": "string"
      },
      "isRead": {
        "type": "boolean"
      },
      "hasAttachments": {
        "type": "boolean"
      },
      "attachmentCount": {
        "type": "number",
        "description": "Number of attachments."
      },
      "importance": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "New Email",
      "is_default": true,
      "description": "A new email was received (below attachment threshold)."
    },
    {
      "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 this polling cycle."
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Failed to fetch email or subscription error."
    }
  ],
  "execution_mode": "async",
  "tags": [
    "email",
    "microsoft",
    "outlook",
    "trigger",
    "incoming"
  ],
  "is_stateful": false,
  "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. 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_email": {
      "type": "string",
      "title": "Mailbox Email",
      "description": "Email address of the mailbox to monitor for new emails.",
      "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."
    },
    "polling_interval": {
      "type": "number",
      "title": "Polling Interval (seconds)",
      "default": 60,
      "description": "How often to check for new emails. Minimum 60 seconds."
    },
    "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. Useful for routing to a dedicated attachment processing node."
    },
    "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_email"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "The incoming email data from Microsoft Graph API.",
  "properties": {
    "id": {
      "type": "string",
      "description": "The message ID. Use this for reply/forward/delete operations."
    },
    "subject": {
      "type": "string"
    },
    "from": {
      "type": "string",
      "description": "Sender email address."
    },
    "to": {
      "type": "array",
      "description": "Recipient email addresses."
    },
    "receivedDateTime": {
      "type": "string",
      "format": "date-time"
    },
    "body": {
      "type": "string",
      "description": "Email body content."
    },
    "bodyPreview": {
      "type": "string"
    },
    "isRead": {
      "type": "boolean"
    },
    "hasAttachments": {
      "type": "boolean"
    },
    "attachmentCount": {
      "type": "number",
      "description": "Number of attachments."
    },
    "importance": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "New Email",
    "is_default": true,
    "description": "A new email was received (below attachment threshold)."
  },
  {
    "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 this polling cycle."
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Failed to fetch email or subscription error."
  }
]
```
