MasterKey can send automatic e-mails (for example reports and notifications) from a mailbox of your own organization in Microsoft 365. To do this, your IT department creates an app registration in your own Microsoft 365 environment, and an administrator enters its details in MasterKey.
This page is intended for your IT department (steps 1 to 5) and for the MasterKey administrator within your organization (steps 6 and 7). Steps 1 to 5 require an account with the Application Administrator role and, for step 5, Exchange Administrator. Allow about 30 minutes.
| Item | Value |
|---|---|
| Type of connection | App-only via Microsoft Graph (OAuth 2.0 client credentials); MasterKey does not sign in a user |
| Supported account types | Accounts in this organizational directory only (single tenant) |
| Redirect URI (callback URL) | Not needed, leave empty |
| Permissions | Mail.Send and Mail.ReadWrite (application permissions, not delegated) |
| Authentication | Client secret, valid for up to 24 months |
| SMTP AUTH | Not needed, may stay disabled |
| DNS (SPF, DKIM, DMARC) | No change needed; the e-mail is sent through your own Microsoft 365 |
| Outbound traffic from MasterKey | login.microsoftonline.com and graph.microsoft.com (HTTPS, port 443) |
| Details for MasterKey | Mailbox address, Directory (tenant) ID, Application (client) ID, value and expiry date of the client secret |
Choose or create the mailbox that MasterKey will send from. We recommend a shared mailbox, for example quality@yourcompany.com; it does not need a license. If replies from recipients should be read, choose a mailbox that someone monitors.
Exchange Online has sending limits per mailbox: at most 10,000 recipients per day and 30 messages per minute. The default maximum message size is 35 MB.
MasterKey mail.With only these permissions the app cannot do anything yet: in step 5 you grant consent, preferably limited to one mailbox.
Treat the secret like a password: do not send it by regular e-mail. Preferably enter it in MasterKey yourself (step 6), together with the MasterKey administrator.
With a regular admin consent, the app may work from and in all mailboxes of your organization. We recommend limiting this to the mailbox from step 1 with RBAC for Applications in Exchange Online. In that case, do not grant admin consent under API permissions (or revoke it via Enterprise applications → MasterKey mail → Permissions), because that consent applies to all mailboxes and cancels the restriction.
Run the following in Exchange Online PowerShell. Use the object ID of the app under Enterprise applications, not the one under App registrations.
Install-Module ExchangeOnlineManagement # once Connect-ExchangeOnline New-ServicePrincipal -AppId <Application (client) ID> -ObjectId <Object ID from Enterprise applications> -DisplayName "MasterKey mail" New-ManagementScope -Name "MasterKey mail" -RecipientRestrictionFilter "PrimarySmtpAddress -eq 'quality@yourcompany.com'" New-ManagementRoleAssignment -App <Application (client) ID> -Role "Application Mail.Send" -CustomResourceScope "MasterKey mail" New-ManagementRoleAssignment -App <Application (client) ID> -Role "Application Mail.ReadWrite" -CustomResourceScope "MasterKey mail"
Check the restriction; both roles must show InScope True. For any other mailbox, InScope should be False:
Test-ServicePrincipalAuthorization -Identity <Application (client) ID> -Resource quality@yourcompany.com
It can take up to 2 hours before Microsoft has applied the permissions everywhere. To allow more mailboxes later, adjust the filter, for example to a mail-enabled security group: -RecipientRestrictionFilter “MemberOfGroup -eq '<DistinguishedName of the group>'”.
If you do not want to restrict the app, click Grant admin consent for <your organization> under API permissions.
Does your organization use Conditional Access for workload identities with a location restriction? Then ask MasterKey for the current outbound IP addresses and allow them for the app MasterKey mail. Regular Conditional Access policies for users do not apply to this app.
An administrator in MasterKey goes to Settings → Application → E-Mail and selects Microsoft 365 as the Mailserver. Fill in:
Click Save and then Send test mail. MasterKey then sends a test e-mail to your own e-mail address. If this fails, MasterKey shows Microsoft's message, for example when the secret is incorrect or the app has no permission for the mailbox (see Common messages).
From 30 days before the expiry date, MasterKey shows a warning under Settings → Application → E-Mail. After the expiry date, MasterKey can no longer send e-mail. Renew the secret in time:
You can stop the connection at any time; MasterKey can then no longer send e-mail from your mailbox:
MasterKey mail, orRemove-ManagementRoleAssignment.Then choose a different mail server in MasterKey under Settings → Application → E-Mail, otherwise no more e-mails will be sent.
| Message contains | Cause |
|---|---|
| AADSTS7000222 | The client secret has expired. Create a new secret (step 7). |
| AADSTS7000215 | The client secret is incorrect; often the Secret ID was entered instead of the Value. |
| AADSTS700016 | The Application (client) ID does not exist in this Microsoft 365 environment. |
| AADSTS90002 | The Directory (tenant) ID does not exist. |
| ErrorAccessDenied / AccessDenied | The app has no permission for this mailbox (step 5). Just changed? Wait up to 2 hours. If it only fails with large attachments, Mail.ReadWrite is missing. |
| ErrorInvalidUser / MailboxNotEnabledForRESTAPI / ResourceNotFound | The mailbox does not exist or is not an Exchange Online mailbox. |
| ErrorMessageSizeExceeded | The e-mail is larger than the mailbox is allowed to send. Increase the maximum send size of the mailbox. |
Still stuck? Contact MasterKey support and include the full message. Never include the client secret.