> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/m/microsoft-exchange-online.md).

# Microsoft Exchange Online

Microsoft Exchange Online is the hosted mail service of Microsoft 365. OctoXLabs runs the `Get-Mailbox` cmdlet through the Exchange Online Admin API and adds the mailboxes to the user inventory.

## Use cases

* List the mailbox owners returned by Exchange Online.

```
Adapters = microsoft-exchange-online
```

* Find Exchange Online users in a given mail domain.

```
Adapters = microsoft-exchange-online AND Domain = example.com
```

## Before you begin

### Network

| Source              | Destination               | Port | Protocol |
| ------------------- | ------------------------- | ---- | -------- |
| OctoXLabs connector | login.microsoftonline.com | 443  | HTTPS    |
| OctoXLabs connector | outlook.office365.com     | 443  | HTTPS    |

### Required permissions

| Scope or role                                                                          | Permission    | Needed for                                 |
| -------------------------------------------------------------------------------------- | ------------- | ------------------------------------------ |
| Exchange.ManageAsAppV2 (Office 365 Exchange Online, application)                       | Admin consent | Calling the Exchange Online Admin API      |
| Recipient Management (Exchange RBAC role group) or Exchange Administrator (Entra role) | Read          | Reading mailbox data through `Get-Mailbox` |

## Create credentials in Microsoft Exchange Online

{% stepper %}
{% step %}

### Create a client secret

In the Microsoft Entra admin center, open the app registration, go to Certificates & Secrets, and select New client secret. Set a description and expiration and select Add. Copy the value immediately.
{% endstep %}

{% step %}

### Add the API permission

Open API Permissions > Add a permission > APIs my organization uses, and search for Office 365 Exchange Online. Select Application permissions, expand Exchange, enable Exchange.ManageAsAppV2, and select Add permissions.
{% endstep %}

{% step %}

### Grant admin consent

Select Grant admin consent for the organization.
{% endstep %}

{% step %}

### Assign a role

Assign the Recipient Management Exchange RBAC role group, or the broader Exchange Administrator Entra role, to the service principal of the app.
{% endstep %}

{% step %}

### Copy the IDs

Copy the Tenant ID (Directory ID) and Application (client) ID.
{% endstep %}
{% endstepper %}

## Connection parameters

| Parameter                         | Required | Type    | Default | Description                                                                                                                                                                                         |
| --------------------------------- | -------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Tenant ID (`tenant_id`)           | Yes      | String  |         | Tenant ID of the Microsoft 365 tenant. Used in the token request and the Admin API URL.                                                                                                             |
| Client ID (`client_id`)           | Yes      | String  |         | Application (client) ID.                                                                                                                                                                            |
| Client Secret (`client_secret`)   | Yes      | String  |         | Client secret value.                                                                                                                                                                                |
| Anchor Mailbox (`anchor_mailbox`) | No       | String  |         | Value for the `X-AnchorMailbox` header. Empty uses the tenant system mailbox. Override only if your tenant needs a specific routing target, for example `AAD-UPN:admin@yourtenant.onmicrosoft.com`. |
| Proxy (`proxy`)                   | No       | String  |         | Proxy host and port, sent as an `http://` proxy URL.                                                                                                                                                |
| Timeout (`timeout`)               | No       | Integer | 30      | Seconds to wait for API responses.                                                                                                                                                                  |

## Troubleshooting

| Error message            | Cause                                                    | Fix                                                                                                     |
| ------------------------ | -------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| Max retries exceeded for | The API kept returning errors, 401 or 429 after retries. | Check the app permissions, the role assignment and the rate limit. The connector retries up to 5 times. |

## Change history
