# Outlook - Attachments

> Download and manage email attachments from Microsoft Outlook via Microsoft Graph API.

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

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

Download and manage email attachments from Microsoft Outlook via Microsoft Graph API.

Dedicated attachment handler for corporate environments with high-volume email processing. Supports filtering by type, size, pagination for emails with many attachments, and streaming to disk for large files.

**Operations:**
- **List:** Get metadata of all attachments (name, type, size) without downloading content.
- **Download:** Download attachment content as base64 or write directly to temporary files.
- **Download All:** Download all attachments from a message with optional filtering.

## 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_mode` (string, optional): Default: `token_owner`. Allowed values: `token_owner`, `other`.
- `mailbox_email` (string, optional, accepts expressions): Shown when: mailbox_mode = `other`.
- `message_source` (string, optional): Incoming: uses the email ID from the previous node. Custom: specify a message ID manually. Default: `incoming`. Allowed values: `incoming`, `custom`.
- `custom_message_id` (string, optional, accepts expressions): Shown when: message_source = `custom`.
- `filter_content_type` (string, optional, accepts expressions): Optional MIME type filter (e.g., "application/pdf", "image/"). Supports prefix matching.
- `filter_min_size` (number, optional): Minimum attachment size in bytes. Useful for filtering out inline images.
- `filter_max_size` (number, optional): Maximum attachment size in bytes.
- `output_mode` (string, optional): Content: returns base64 in payload. File: writes to /tmp/ and returns file paths (recommended for large attachments). Default: `content`. Allowed values: `content`, `file`.

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

- `success` (default): Attachments Found
- `no_attachments`: No Attachments
- `error`: Error

## Input contract

- `id` (string, optional): Message ID from the trigger or previous node.

## Output contract

- `attachments` (array, optional): List of attachments with metadata and content/path.
- `count` (number, optional): Number of attachments found.

## In expressions

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

- `$("Outlook - Attachments").item.json.attachments` (array) = `[…] (1)`: List of attachments with metadata and content/path.
- `$("Outlook - Attachments").item.json.count` (number) = `1`: Number of attachments found.


## How it works

Downloads the attachments of one Outlook message through Microsoft Graph, filters them by MIME type and size, and returns them as base64 content or as files on the orchestrator.

1. Resolves the node config and requires `connection_id`. Gets a Graph token: with `client_id`, `client_secret` and `tenant_id` in the credential secret it requests an app-only token (client credentials); otherwise it uses the secret's `token` or `access_token` as is.
2. Targets `/users/<mailbox_email>` when `mailbox_mode` is `other`, otherwise `/me`.
3. Takes the message id from `custom_message_id` when `message_source` is `custom`, otherwise from the incoming item's `id`.
4. Lists every attachment of the message, following `@odata.nextLink` pages.
5. Keeps the attachments whose `contentType` starts with `filter_content_type` and whose `size` is within `filter_min_size` and `filter_max_size`.
6. Returns `no_attachments` when nothing is left. Otherwise returns `success` with `content_bytes` (base64) per attachment, or, in `file` mode, writes each one to a new temporary directory and returns its `file_path`.

## In a workflow

### Node

```json
{
  "node_id": "node-get-pdfs",
  "label": "Get PDF attachments",
  "operator_slug": "connectors.microsoft.outlook.attachments",
  "operator_version": "1.0.0",
  "config": {
    "connection_id": "pi-credential-xxxx",
    "mailbox_mode": "other",
    "mailbox_email": "support@example.com",
    "message_source": "incoming",
    "filter_content_type": "application/pdf",
    "filter_min_size": 1024,
    "output_mode": "content"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "attachments": [
      {
        "id": "AAMkAGI2THVSAAA=",
        "name": "invoice-2026-0418.pdf",
        "content_type": "application/pdf",
        "size": 48213,
        "content_bytes": "JVBERi0xLjcKJc...",
        "is_inline": false
      }
    ],
    "count": 1
  },
  "port": "success"
}
```

## Output ports (behaviour in the code)

### `success`

At least one attachment passed the filters. In `file` mode each item has `file_path` instead of `content_bytes`.

```json
{
  "attachments": [
    {
      "id": "AAMkAGI2THVSAAA=",
      "name": "invoice-2026-0418.pdf",
      "content_type": "application/pdf",
      "size": 48213,
      "content_bytes": "JVBERi0xLjcKJc...",
      "is_inline": false
    }
  ],
  "count": 1
}
```

### `no_attachments`

The message has no attachments, or none passed the filters.

```json
{
  "attachments": [],
  "count": 0
}
```

### `error`

A validation failed (the output is the envelope `{ ok, errors, port }`) or a Graph call failed (the output is `{ error, response }` with Graph's error body).

```json
{
  "ok": false,
  "errors": [
    "Failed to resolve Microsoft 365 access token"
  ],
  "port": "error"
}
```

## Behaviour in the code

- `mailbox_mode`: App-only tokens (client credentials) have no `/me`; use `other` with `mailbox_email` for them.
- `filter_content_type`: Case-sensitive prefix match on `contentType` (for example `image/` or `application/pdf`).
- `output_mode`: `file` writes under the orchestrator's temporary directory using the attachment name; two attachments with the same name overwrite each other, and the files are not cleaned up by the node.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Microsoft 365 credential is required` | `error` | `connection_id` is empty. |
| `Failed to resolve Microsoft 365 access token` | `error` | The credential could not be resolved, the token request failed, or the secret has neither client credentials nor a token. The underlying reason is not reported. |
| `Message ID is required. Ensure the previous node outputs an email with an ID, or select "Custom" and provide a Message ID.` | `error` | The incoming item has no `id` and no custom id is set. |
| `Request failed with status code <status>` | `error` | Graph rejected the call: 404 for an unknown message id or mailbox, 401/403 for an expired token or missing `Mail.Read` permission. See `response` for Graph's error. |

## Notes and limits

- An OAuth access token stored in the credential is used as is and never refreshed; when it expires Graph returns 401.
- Item and reference attachments carry no `contentBytes`: `content_bytes` is `null`, and in `file` mode no file is written although `file_path` is returned.
- `content` mode puts every attachment in the workflow state as base64; prefer `file` for large files. The node does not retry.


## Contracts (JSON Schema)

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

```json
{
  "slug": "connectors.microsoft.outlook.attachments",
  "name": "Outlook - Attachments",
  "category": "integrations",
  "version": "1.0.0",
  "description": "Download and manage email attachments from Microsoft Outlook via Microsoft Graph API.\n\n  Dedicated attachment handler for corporate environments with high-volume email processing. Supports filtering by type, size, pagination for emails with many attachments, and streaming to disk for large files.\n\n  **Operations:**\n  - **List:** Get metadata of all attachments (name, type, size) without downloading content.\n  - **Download:** Download attachment content as base64 or write directly to temporary files.\n  - **Download All:** Download all attachments from a message with optional filtering.",
  "capabilities": [
    "email",
    "attachments",
    "microsoft",
    "outlook",
    "office365"
  ],
  "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_mode": {
        "type": "string",
        "title": "Mailbox",
        "enum": [
          "token_owner",
          "other"
        ],
        "default": "token_owner"
      },
      "mailbox_email": {
        "type": "string",
        "title": "Mailbox Email",
        "format": "expression",
        "displayOptions": {
          "show": {
            "mailbox_mode": [
              "other"
            ]
          }
        }
      },
      "message_source": {
        "type": "string",
        "title": "Message Source",
        "enum": [
          "incoming",
          "custom"
        ],
        "default": "incoming",
        "description": "Incoming: uses the email ID from the previous node. Custom: specify a message ID manually."
      },
      "custom_message_id": {
        "type": "string",
        "title": "Message ID",
        "format": "expression",
        "displayOptions": {
          "show": {
            "message_source": [
              "custom"
            ]
          }
        }
      },
      "filter_content_type": {
        "type": "string",
        "title": "Filter by Type",
        "description": "Optional MIME type filter (e.g., \"application/pdf\", \"image/\"). Supports prefix matching.",
        "format": "expression"
      },
      "filter_min_size": {
        "type": "number",
        "title": "Min Size (bytes)",
        "description": "Minimum attachment size in bytes. Useful for filtering out inline images."
      },
      "filter_max_size": {
        "type": "number",
        "title": "Max Size (bytes)",
        "description": "Maximum attachment size in bytes."
      },
      "output_mode": {
        "type": "string",
        "title": "Output Mode",
        "enum": [
          "content",
          "file"
        ],
        "default": "content",
        "description": "Content: returns base64 in payload. File: writes to /tmp/ and returns file paths (recommended for large attachments)."
      },
      "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"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "id": {
        "type": "string",
        "description": "Message ID from the trigger or previous node."
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "attachments": {
        "type": "array",
        "description": "List of attachments with metadata and content/path."
      },
      "count": {
        "type": "number",
        "description": "Number of attachments found."
      }
    }
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Attachments Found",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "no_attachments",
      "label": "No Attachments",
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "tags": [
    "email",
    "attachments",
    "microsoft",
    "outlook",
    "download"
  ],
  "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_mode": {
      "type": "string",
      "title": "Mailbox",
      "enum": [
        "token_owner",
        "other"
      ],
      "default": "token_owner"
    },
    "mailbox_email": {
      "type": "string",
      "title": "Mailbox Email",
      "format": "expression",
      "displayOptions": {
        "show": {
          "mailbox_mode": [
            "other"
          ]
        }
      }
    },
    "message_source": {
      "type": "string",
      "title": "Message Source",
      "enum": [
        "incoming",
        "custom"
      ],
      "default": "incoming",
      "description": "Incoming: uses the email ID from the previous node. Custom: specify a message ID manually."
    },
    "custom_message_id": {
      "type": "string",
      "title": "Message ID",
      "format": "expression",
      "displayOptions": {
        "show": {
          "message_source": [
            "custom"
          ]
        }
      }
    },
    "filter_content_type": {
      "type": "string",
      "title": "Filter by Type",
      "description": "Optional MIME type filter (e.g., \"application/pdf\", \"image/\"). Supports prefix matching.",
      "format": "expression"
    },
    "filter_min_size": {
      "type": "number",
      "title": "Min Size (bytes)",
      "description": "Minimum attachment size in bytes. Useful for filtering out inline images."
    },
    "filter_max_size": {
      "type": "number",
      "title": "Max Size (bytes)",
      "description": "Maximum attachment size in bytes."
    },
    "output_mode": {
      "type": "string",
      "title": "Output Mode",
      "enum": [
        "content",
        "file"
      ],
      "default": "content",
      "description": "Content: returns base64 in payload. File: writes to /tmp/ and returns file paths (recommended for large attachments)."
    },
    "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"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "Message ID from the trigger or previous node."
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "attachments": {
      "type": "array",
      "description": "List of attachments with metadata and content/path."
    },
    "count": {
      "type": "number",
      "description": "Number of attachments found."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "success",
    "label": "Attachments Found",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "no_attachments",
    "label": "No Attachments",
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "supports_condition": false
  }
]
```
