---
title: "Connect Microsoft 365 mail with OAuth2"
site: admin
version: 1.11
versions: "all"
url: https://docs-new.servicely.ai/admin/1.11/messaging/connect-microsoft-365-oauth2/
type: task
application: system_email
last_updated: 2026-10-18
commit: 50111ae9bd3b
---


Use OAuth2 when an IMAP or SMTP messaging account connects to a Microsoft 365 mailbox, because Microsoft no longer accepts password authentication. It is for administrators who manage both the Microsoft Entra ID app registration and the Servicely messaging accounts.

## Before you begin

- You need the `administrator` role in Servicely.
- You need permission to create app registrations in Microsoft Entra ID.
- You can sign in to Microsoft as the mailbox user. That user must hold a mailbox licence.
- The IMAP or SMTP messaging account exists. See [Create a messaging account](page:messaging/messaging-accounts).

Servicely uses the same OAuth providers and API outbound tokens as its other integrations. [Outbound credentials](page:integrations/outbound-credentials) describes every field.

## Steps

<Steps>
  <Step>
    In the Azure portal, open **App registrations** and register a new application for Servicely. Note its application (client) ID and its tenant ID.
  </Step>
  <Step>
    In Servicely, create a **System OAuth Provider** record from the **Microsoft** template. Enter the **Client ID**. Make sure the tenant ID appears in the **Authorization URL** and **Token URL**. Set **Grant type** to **Authorization Code**.

    <Image src="asset:screenshots/admin/messaging-connect-microsoft-365-oauth2/image.png">A System OAuth Provider form with the template menu open on Microsoft and the Redirect URL ending in /sso/oauth_callback.</Image>
  </Step>
  <Step>
    Copy the provider's **Redirect URL**. In the app registration's overview, open **Redirect URIs**, select **Add a platform**, choose **Web** and paste the URL. Save. The overview now shows "1 web" next to **Redirect URIs**.
  </Step>
  <Step>
    Under **API permissions**, add these delegated Microsoft Graph permissions: **email**, **IMAP.AccessAsUser.All**, **offline_access**, **openid**, **SMTP.Send** and **User.Read**.

    <Image src="asset:screenshots/admin/messaging-connect-microsoft-365-oauth2/image-5.png">The API permissions page listing the six delegated Microsoft Graph permissions, each granted.</Image>
  </Step>
  <Step>
    Under **Certificates & secrets**, add a client secret. Copy its value into the provider's **Client Secret** field and save the provider.
  </Step>
  <Step>
    Create a **System API Outbound Token**. Set **Type** to **OAuth2**, select the provider in **OAuth Provider**, and enter the **Scopes** below.

    ```
    offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send openid email
    ```

    <Image src="asset:screenshots/admin/messaging-connect-microsoft-365-oauth2/image-2.png">A new System API Outbound Token of type OAuth2 with the email scopes entered and State New.</Image>
  </Step>
  <Step>
    Save the token and select **Get authorization token**. Sign in to Microsoft as the mailbox user, not as an administrator.
  </Step>
  <Step>
    Select **Accept** on the Microsoft permissions page. Microsoft returns you to Servicely.

    <Image src="asset:screenshots/admin/messaging-connect-microsoft-365-oauth2/image-3.png">The Microsoft "Permissions requested" page asking to read and write mail and send email from the mailbox.</Image>
  </Step>
  <Step>
    Check that the token's **State** is Ready and **Expires** holds a date.

    <Image src="asset:screenshots/admin/messaging-connect-microsoft-365-oauth2/image-4.png">The System API Outbound Token after authorisation, with State Ready and an Expires date.</Image>
  </Step>
  <Step>
    Open the messaging account. Set **Authentication type** to **OAuth 2** and select the token in **Outbound API token**. Save, then select **Test Connection**.

    <Image src="asset:screenshots/admin/messaging-connect-microsoft-365-oauth2/image-6.png">An IMAP (Inbound Email) messaging account using OAuth 2 and the outbound API token.</Image>
  </Step>
</Steps>

<Callout type="warning">
  If you first authorise as a Microsoft Entra ID administrator with **OAuth Prompt** set to consent, Microsoft offers to consent for the whole organisation. Accepting fills the app registration's permissions. Afterwards, change **OAuth Prompt** to another value, for example select_account, and authorise again as the mailbox user.
</Callout>

<!-- source: platform_integration/data/AvailableValue?Table=SystemAPIOutboundToken&Field=OAuthPrompt -->
| OAuth Prompt | Use |
| --- | --- |
| login | Microsoft asks for credentials even if a session exists |
| select_account | Microsoft asks which account to use |
| consent | Microsoft shows the consent page |
| none | Microsoft shows no prompt |

## Result

The messaging account authenticates with the token instead of a password, and its connection test passes. Servicely renews the token with the offline_access scope. If the test fails or mail does not arrive, see [Troubleshoot messaging accounts](page:messaging/troubleshoot-messaging-accounts).

## Related

- [Create a messaging account](page:messaging/messaging-accounts)
- [Connect Microsoft 365 mail with Graph API](page:messaging/connect-microsoft-365-graph-api)
- [Outbound credentials](page:integrations/outbound-credentials)
- [Troubleshoot messaging accounts](page:messaging/troubleshoot-messaging-accounts)
