Microsoft 365 mail and Teams
Send platform mail through Microsoft 365 with an app registration and post notifications to Microsoft Teams with a Workflows URL.
Microsoft has retired basic authentication (user name and password) for SMTP in Exchange Online, and the Office 365 connectors ("Incoming Webhook") in Teams. This page shows how to send the platform's mail (activation, password reset, notifications, reports, test mail) through Microsoft 365 with an app registration, and how to post notifications to Teams with a Workflows URL.
Which mail provider
Open Settings > Mail server as system administrator and pick the Mail provider:
| Provider | How it sends | Microsoft permission | When to use |
|---|---|---|---|
| Microsoft 365 (Graph API) | HTTPS to Microsoft Graph sendMail | Microsoft Graph, application permission Mail.Send | Recommended. No SMTP port needed, works through an HTTPS proxy |
| Microsoft 365 SMTP (OAuth2 client credentials) | smtp.office365.com:587, STARTTLS, XOAUTH2 | Office 365 Exchange Online, application permission SMTP.SendAsApp | When outbound mail must go over SMTP |
| Office 365 | SMTP with a signed-in user (authorization code and refresh token) | Delegated SMTP.Send | Existing setups; the token must be renewed when the refresh token expires |
| Custom, Google, SendGrid | SMTP | Unchanged |
Both Microsoft 365 providers use the client-credentials flow: the server asks https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token for a token with its own client ID and secret and keeps it until it expires. Nobody has to sign in, and no refresh token runs out.
Register the app in Microsoft Entra ID
- Open the Microsoft Entra admin center, App registrations > New registration. Name it, for example "Aniston Nexus mail", choose Accounts in this organizational directory only and leave the redirect URI empty.
- On the Overview page copy the Directory (tenant) ID and the Application (client) ID.
- Certificates & secrets > Client secrets > New client secret. Copy the secret's Value right away (the Secret ID is not the secret). Note the expiry date: mail stops when the secret expires.
- Add the permission for the provider you chose (next two sections), then Grant admin consent.
Graph API permission
- API permissions > Add a permission > Microsoft Graph > Application permissions > Mail > Mail.Send.
- Grant admin consent for <your organization>. The status column must show a green tick.
- Recommended: without a limit,
Mail.Sendlets the app send as any mailbox in the organization. Limit it to the sender mailbox with Exchange Online RBAC for Applications, or with an application access policy:
New-DistributionGroup -Name "Nexus mail senders" -Type Security -Members noreply@contoso.com
New-ApplicationAccessPolicy -AppId <client ID> -PolicyScopeGroupId "Nexus mail senders" -AccessRight RestrictAccess -Description "Aniston Nexus mail"
Test-ApplicationAccessPolicy -AppId <client ID> -Identity noreply@contoso.com
SMTP permission
- **API permissions > Add a permission > APIs my organization uses > Office 365 Exchange Online > Application permissions > SMTP.SendAsApp, then Grant admin consent**.
- Register the app's service principal in Exchange Online and give it the sender mailbox. Use the Object ID from Enterprise applications (not the one on the app registration page):
Connect-ExchangeOnline
New-ServicePrincipal -AppId <client ID> -ObjectId <enterprise application object ID>
Add-MailboxPermission -Identity noreply@contoso.com -User <enterprise application object ID> -AccessRights FullAccess
- Turn on authenticated SMTP for that mailbox (it is off in many tenants):
Set-CASMailbox -Identity noreply@contoso.com -SmtpClientAuthenticationDisabled $false
Enter the settings
In Settings > Mail server:
| Field | Value |
|---|---|
| Mail from | The sender mailbox, a display name is fine: Aniston Nexus <noreply@contoso.com> |
| Mail provider | Microsoft 365 (Graph API) or Microsoft 365 SMTP (OAuth2 client credentials) |
| Directory (tenant) ID | From the app's Overview page |
| Application (client) ID | From the app's Overview page |
| Client secret | The secret's Value. It is stored like the SMTP password: never sent back to the browser. Tick Change client secret to replace it |
| Sender mailbox (UPN) | The licensed Exchange Online mailbox that sends, for example noreply@contoso.com |
| Save to Sent Items | Graph only. Off by default so a no-reply mailbox does not fill up |
For SMTP the connection settings are filled in for you (smtp.office365.com, port 587, STARTTLS, TLS 1.2). An outbound proxy set under the connection settings is also used for the Microsoft sign-in and Graph calls.
Click Send test mail: it uses the values in the form, also before you save. The mail goes to the system administrator's own address.
National clouds: set the optional keys msLoginBaseUrl (for example https://login.microsoftonline.us) and msGraphBaseUrl (for example https://graph.microsoft.us) in the mail admin setting through the API.
Error messages
| Message starts with | Fix |
|---|---|
| Invalid client secret | Paste the secret's Value, not the Secret ID |
| The client secret has expired | Create a new secret, enter it with Change client secret |
| Application (client) ID not found | Wrong client ID, or the app is in another tenant |
| Directory (tenant) ID not found | Copy the tenant ID from the app's Overview page |
| Mail.Send application permission missing | Add Microsoft Graph application permission Mail.Send and grant admin consent; if an access policy limits the app, include the sender mailbox |
| Sender mailbox ... not found | The UPN is wrong or the mailbox has no Exchange Online licence |
| The app may not send as the "Mail from" address | Use the sender mailbox as Mail from, or give the mailbox Send As rights |
| The mail is too large | Graph accepts about 3 MB of attachments in one request; send large reports as links |
| 535 5.7.3 Authentication unsuccessful (SMTP) | Service principal or FullAccess missing, or SMTP AUTH is off for the mailbox |
Microsoft Teams
Notification recipients of type Microsoft Teams post a card to a channel.
- In Teams open the channel, ... > Workflows, and choose the template **Post to a channel when a webhook request is received**. Pick the team and channel and finish the wizard.
- Copy the URL it shows. It looks like
https://...logic.azure.com/workflows/...orhttps://...environment.api.powerplatform.com/powerautomate/automations/direct/workflows/...and must keep itssig=parameter. - In Notification center > Recipients > Add recipient, type Microsoft Teams, paste the URL as Workflow URL and give the channel a name.
The platform sends an Adaptive Card (version 1.4) in the format the Workflows template expects: {"type":"message","attachments":[{"contentType":"application/vnd.microsoft.card.adaptive","content":{...}}]}. The template's theme colour becomes the card background and the text colour is chosen to stay readable; the button becomes an Open URL action. A workflow URL always gets an Adaptive Card, even when Use old API is on.
Old Office 365 connector URLs (https://<tenant>.webhook.office.com/webhookb2/...) still get the legacy MessageCard while Use old API is on. When Microsoft refuses such a URL, the notification log says so and names the Workflows template to use instead.
If a workflow URL answers 401, 403 or 404, the workflow was turned off or deleted, or the URL was copied without its sig= parameter. A workflow posts as the user who created it (or as the Flow bot); that user must stay a member of the channel.