Aniston NexusDocs
Open Aniston Nexus

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:

ProviderHow it sendsMicrosoft permissionWhen to use
Microsoft 365 (Graph API)HTTPS to Microsoft Graph sendMailMicrosoft Graph, application permission Mail.SendRecommended. No SMTP port needed, works through an HTTPS proxy
Microsoft 365 SMTP (OAuth2 client credentials)smtp.office365.com:587, STARTTLS, XOAUTH2Office 365 Exchange Online, application permission SMTP.SendAsAppWhen outbound mail must go over SMTP
Office 365SMTP with a signed-in user (authorization code and refresh token)Delegated SMTP.SendExisting setups; the token must be renewed when the refresh token expires
Custom, Google, SendGridSMTPUnchanged

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

  1. 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.
  2. On the Overview page copy the Directory (tenant) ID and the Application (client) ID.
  3. 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.
  4. Add the permission for the provider you chose (next two sections), then Grant admin consent.

Graph API permission

  1. API permissions > Add a permission > Microsoft Graph > Application permissions > Mail > Mail.Send.
  2. Grant admin consent for <your organization>. The status column must show a green tick.
  3. Recommended: without a limit, Mail.Send lets 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

  1. **API permissions > Add a permission > APIs my organization uses > Office 365 Exchange Online > Application permissions > SMTP.SendAsApp, then Grant admin consent**.
  2. 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
  1. 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:

FieldValue
Mail fromThe sender mailbox, a display name is fine: Aniston Nexus <noreply@contoso.com>
Mail providerMicrosoft 365 (Graph API) or Microsoft 365 SMTP (OAuth2 client credentials)
Directory (tenant) IDFrom the app's Overview page
Application (client) IDFrom the app's Overview page
Client secretThe 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 ItemsGraph 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 withFix
Invalid client secretPaste the secret's Value, not the Secret ID
The client secret has expiredCreate a new secret, enter it with Change client secret
Application (client) ID not foundWrong client ID, or the app is in another tenant
Directory (tenant) ID not foundCopy the tenant ID from the app's Overview page
Mail.Send application permission missingAdd Microsoft Graph application permission Mail.Send and grant admin consent; if an access policy limits the app, include the sender mailbox
Sender mailbox ... not foundThe UPN is wrong or the mailbox has no Exchange Online licence
The app may not send as the "Mail from" addressUse the sender mailbox as Mail from, or give the mailbox Send As rights
The mail is too largeGraph 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.

  1. 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.
  2. Copy the URL it shows. It looks like https://...logic.azure.com/workflows/... or https://...environment.api.powerplatform.com/powerautomate/automations/direct/workflows/... and must keep its sig= parameter.
  3. 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.