Restrict M365 Graph API Mail.Send to a Mailbox

This article builds on Configure Microsoft 365 Graph API for WorkflowMail (formerly FlowMail), which sets up an organization-wide Mail.Send permission. Follow the main guide first if you haven't created the app yet. The steps below restrict the app so it can send email from only one mailbox.
Caution: Please treat this instruction with caution. It may not be tested with the latest Microsoft 365 Graph API updates and we are not responsible for any possible consequences of completing the steps. Always double check what you're going to change / execute and do not launch any commands you are unsure about. This guide is intended for system administrators; if you are not familiar with Microsoft 365, Exchange Online or PowerShell, please consult your IT administrator before proceeding.
1. Create the app
Complete the part of the main guide that applies to app creation (register the app, copy the Tenant ID and Client ID, create a client secret). If you follow the original guide, leave the Mail.Send consent described by that guide in place – it will be scoped to only one sender below. If you follow the preferred approach, do not grant tenant-wide consent. You can remove all the settings from WorkflowMail to be safe: nothing will use this app until you finish the setup.
Preferred approach (what worked for a customer): avoid granting tenant-wide Mail.Send consent in Entra and rely solely on Exchange Online Application RBAC (see below). In that case skip step 8.
2. Collect the enterprise application identifiers
In Microsoft Entra admin center, open Enterprise applications (not App registrations), open the app and copy:
- Application ID – same value as the app's Client ID
- Object ID – the enterprise application's object ID
3. Connect to Exchange Online PowerShell
An Exchange Administrator, or a member of Organization Management, runs:
Install-Module ExchangeOnlineManagement
Connect-ExchangeOnline
If your tenant has not been customized for organization-level settings yet, you may also need to run:
Enable-OrganizationCustomization
This is required before scoped role assignments can be created. Changes may take time to propagate (up to 2 hours).
4. Create the Exchange service principal
New-ServicePrincipal -AppId "<Application ID>" -ObjectId "<Enterprise application Object ID>" -DisplayName "WorkflowMail"
5. Scope it to one mailbox
Use that mailbox's primary SMTP address. An alias will not match.
New-ManagementScope -Name "WorkflowMail sender" -RecipientRestrictionFilter "PrimarySmtpAddress -eq 'sender@example.com'"
6. Assign Application Mail.Send to that scope
New-ManagementRoleAssignment -App "<Application ID>" -Role "Application Mail.Send" -CustomResourceScope "WorkflowMail sender"
Delegation error: you may see an error such as "You don't have access to create, change, or remove the ... Mail.Send management role assignment. You must be assigned by delegating role assignment to the management role or its parent in the hierarchy without a scope restriction." Make sure your signed-in administrator is an effective user of the enabled Application Mail.Send delegating assignment through Organization Management, with RecipientWriteScope set to Organization and no custom scopes. If the identifiers and mailbox scope are correct but it still fails, it may be a propagation delay after enabling organization customisation – retry later (up to 2 hours).
7. Check the scope
Test-ServicePrincipalAuthorization -Identity "<Application ID>" -Resource "sender@example.com"
Test-ServicePrincipalAuthorization -Identity "<Application ID>" -Resource "someone-else@example.com"
Application Mail.Send should show InScope = True for the sender and False for the other mailbox. This test does not see Entra permissions, so it can look restricted while tenant-wide Mail.Send is still in effect.
8. Remove the tenant-wide Graph Mail.Send permission
Remove the tenant-wide Graph Mail.Send permission, including its admin consent. Do this only after step 7. Until it's removed, Exchange RBAC and the Entra grant are combined, and the app can still send as every mailbox.
If you never granted tenant-wide consent (see the preferred approach in step 1), skip this step.
9. Test in WorkflowMail
Note: Microsoft 365 changes can take time to propagate. After making any changes in your Microsoft account, please wait about 60–120 minutes (in some cases up to 2 hours) before using the Microsoft app and its credentials in WorkflowMail.
Then use the settings with WorkflowMail and send a test email using Flow. A send with a mailbox outside of the scope should fail with a 4xx error code.