Many organizations need to restrict specific accounts—such as contractors, kiosk/shared workstations, internal-only service accounts, or students—so they can exchange email internally while being blocked from sending messages to external Internet domains.
In Exchange Online and Exchange Server Subscription Edition (SE), the cleanest and most auditable way to enforce this is with a Mail Flow Rule (Transport Rule) scoped to a security or distribution group, combined with an optional exception list for approved partner domains.
External Mail Restriction Flow
Method 1: Create the Restriction Rule via PowerShell (Recommended)
Using PowerShell works identically in Exchange Online (Connect-ExchangeOnline) and Exchange Server SE / 2019 (Exchange Management Shell).
Step 1: Create a Mail-Enabled Security Group
New-DistributionGroup -Name "Internal-Only-Senders" `
-Alias "InternalOnlySenders" `
-Type "Security" `
-PrimarySmtpAddress "[email protected]"
# Add restricted users to the group
Add-DistributionGroupMember -Identity "Internal-Only-Senders" -Member "[email protected]"
Step 2: Create the Transport Rule
New-TransportRule -Name "Block External Email for Internal-Only Senders" `
-FromMemberOf "[email protected]" `
-SentToScope "NotInOrganization" `
-RejectMessageReasonText "You are not authorized to send email to recipients outside the organization." `
-RejectMessageEnhancedStatusCode "5.7.1" `
-StopRuleProcessing $true `
-Enabled $true `
-Comments "Restricts designated accounts from external outbound mail flow."
Optional: Allow Specific Partner Domains
If restricted users must still email a specific external domain (for example, a parent company or payroll vendor), add -ExceptIfRecipientDomainIs:
Set-TransportRule -Identity "Block External Email for Internal-Only Senders" `
-ExceptIfRecipientDomainIs @("trustedpartner.com", "benefitsvendor.com")
Method 2: Exchange Admin Center (Modern EAC)
- Sign in to the Exchange Admin Center (
admin.exchange.microsoft.com). - Navigate to Mail flow > Rules > Add a rule > Create a new rule.
- Name:
Block External Email for Internal-Only Senders. - Apply this rule if...:
- The sender > is a member of this group > select Internal-Only-Senders.
- Click + to add a second condition: The recipient > is external/internal > Outside the organization.
- Do the following...:
- Block the message > reject the message and include an explanation.
- Enter the explanation text and status code 5.7.1.
- (Optional) Under Except if..., add The recipient > domain is for any approved external domains.
- Set rule mode to Enforce (or Test with Policy Tips during a pilot) and click Finish.
Verify & Audit Rule Enforcement
Confirm the rule is enabled and check its priority order:
Get-TransportRule -Identity "Block External Email for Internal-Only Senders" |
Select-Object Name, State, Priority, Mode, RejectMessageEnhancedStatusCode
In Exchange Online, allow up to 15–30 minutes for transport rule replication across all Microsoft 365 datacenter edges before testing. You can confirm blocked attempts in EAC > Mail flow > Message trace by filtering for status Failed with reason 550 5.7.1.
đź’¬ Reader Comments & Feedback
Did this runbook help, or did Microsoft change a cmdlet or UI menu? Share your feedback below.
Leave a Comment or Report an Update