Block Automatic External Email Forwarding in Exchange Online
In this article
Yes, you can block automatic external email forwarding in Exchange Online while still allowing approved exceptions by using a combination of transport rules and PowerShell cmdlets.
What You’ll Need
- Global or Exchange Administrator credentials for your Microsoft 365 tenant.
- PowerShell 7 (or Windows PowerShell 5.1) installed on a workstation.
- The Exchange Online PowerShell V2 module (EXO V2).
- Basic familiarity with PowerShell syntax and Exchange transport rules.
- Access to the Microsoft 365 admin center (optional for verification).
Step‑by‑Step
- Open PowerShell and install the EXO V2 module (if not already installed). Run:
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUser
This command downloads the official Microsoft module needed to connect to Exchange Online. - Connect to Exchange Online. Execute:
Connect-ExchangeOnline -UserPrincipalName youradmin@yourdomain.com
Replaceyouradmin@yourdomain.comwith your admin UPN. You will be prompted for credentials and MFA if enabled. - Create a transport rule that blocks automatic forwarding to external domains. Use the following cmdlet:
New-TransportRule -Name "Block Automatic External Forwarding" \ -SentToScope NotInOrganization \ -FromScope InOrganization \ -MessageTypeMatches AutoForward \ -RejectMessageReasonText "Automatic forwarding to external recipients is disabled by policy."This rule matches any message that originates inside the organization, is an automatic forward, and is destined for a recipient outside the tenant, then rejects it with a clear error message. - Add an exception for approved mailboxes or domains. Suppose you have a list of mailboxes that are allowed to forward externally (e.g.,
john.doe@contoso.comandjane.smith@contoso.com). Create an exception rule:New-TransportRule -Name "Allow Approved Forwarding" \ -SentToScope NotInOrganization \ -FromScope InOrganization \ -MessageTypeMatches AutoForward \ -FromMemberOf "Approved Forwarders" \ -StopRuleProcessing $trueBefore running this, you must create a mail‑enabled security group calledApproved Forwardersand add the approved users to it. The-StopRuleProcessing $trueflag ensures that once this rule matches, the blocking rule is bypassed. - Verify the rules are in place. List the rules with:
Get-TransportRule | Format-Table Name,Enabled,Priority
Ensure "Block Automatic External Forwarding" has a lower priority number (higher priority) than the exception rule, or explicitly set priorities usingSet-TransportRule -Identity "Block Automatic External Forwarding" -Priority 0and-Priority 1for the exception. - Test the configuration. From a regular mailbox, set up an automatic forward to an external address (e.g.,
user@external.com) and send a test message. You should receive a Non‑Delivery Report (NDR) with the rejection text you defined. Then repeat the test using an account that belongs to theApproved Forwardersgroup; the forward should succeed. - Document the change. Record the rule names, priorities, and the list of approved users in a change‑management log. This helps future admins understand why forwarding behaves the way it does.
- Disconnect the PowerShell session. Run:
Disconnect-ExchangeOnline -Confirm:$false
This cleans up the session and releases resources.
Common Mistakes
- Creating the exception rule after the block rule without adjusting priorities. Exchange processes rules in order of priority; if the block rule runs first, the exception never gets evaluated.
- Using
-MessageTypeMatches AutoForwardincorrectly. The parameter only matches messages generated by the Outlook client’s automatic‑forward feature, not manual forwards. For manual forwards, you would need a different condition (e.g.,-HeaderMatchesSubject "FW:"), but the policy described here targets automatic forwards only. - Forgetting to add approved users to the
Approved Forwardersgroup. The exception rule will never fire if the group is empty. - Applying the rule to the wrong scope. Using
-SentToScope InOrganizationinstead ofNotInOrganizationwould block internal forwards rather than external ones. - Neglecting to test with both a blocked and an allowed scenario. Without testing, you cannot confirm that the rule order works as intended.
Tips
- Use descriptive rule names that include the date of creation. This makes future audits easier.
- Consider adding a
-Commentsparameter to each rule to store the business justification.New-TransportRule -Name "Block Automatic External Forwarding" … -Comments "Policy change 2024‑03‑01: Prevent data leakage"
- If you have many approved mailboxes, manage them through a dynamic group based on an Azure AD attribute (e.g.,
extensionAttribute1 = "AllowExternalForward") instead of a static security group. - Enable mail flow logging for the two rules. In the Exchange admin center, go to Mail flow > Rules, select the rule, and turn on "Audit this rule". This will write each match to the audit log, useful for compliance reporting.
- Combine this transport‑rule approach with a Data Loss Prevention (DLP) policy that scans for sensitive information before forwarding. That adds a second layer of protection.
Troubleshooting
If forwarding still works for non‑approved users, follow these checks in order:
- Rule priority order. Run
Get-TransportRule | Sort-Object Priorityand verify that the block rule has a lower (numerically smaller) priority than the exception rule. - Rule activation status. Ensure both rules are enabled (
Enabled = True). UseSet-TransportRule -Identity "Block Automatic External Forwarding" -Enabled $trueif needed. - Scope verification. Double‑check that
-SentToScope NotInOrganizationis present. A typo likeNotInOrganizatonwill cause the rule to be ignored. - Group membership. Run
Get-DistributionGroupMember "Approved Forwarders"to confirm the expected users appear. - Message type. Verify the forward is truly automatic. Outlook’s “Rules → Forward to” creates an automatic forward; a manual forward (clicking Forward) will not match
AutoForwardand will bypass the rule. If you need to block manual forwards as well, create an additional rule that looks for the "FW:" subject prefix. - Replication delay. After creating or modifying rules, allow up to 15 minutes for the changes to propagate across all Exchange transport nodes.
- Check the audit log. In the Security & Compliance Center, search the audit log for events with the operation
Set-TransportRuleto see if any other admin has overridden your settings. - PowerShell errors. If any cmdlet returns an error, read the error message carefully. Common issues include missing permissions (you need the
Mail Flowrole) or the EXO module not being loaded.
Frequently Asked Questions
Can I block forwarding for a single mailbox instead of the whole organization?
Yes. Use the -From parameter in New-TransportRule to target a specific user, e.g., -From "user@contoso.com". Combine it with the same -MessageTypeMatches AutoForward condition.
Will this rule affect mailbox delegates who forward on behalf of the owner?
Delegates generate a forward that is still considered an automatic forward if the original message triggers the forward rule. The transport rule will apply unless you add an explicit exception for the delegate’s address.
Do I need to restart any services after creating the rule?
No. Transport rules are applied in real time once they are saved. Only a short propagation period is required.
Is there a way to receive a notification when a blocked forward attempt occurs?
Yes. Add the -SendNotificationTo parameter to the block rule, specifying an admin mailbox. Example:
New-TransportRule -Name "Block Automatic External Forwarding" … -SendNotificationTo admin@contoso.com
Can I use the Exchange admin center (EAC) instead of PowerShell?
The EAC provides a UI for creating transport rules, but the AutoForward condition and the ability to reference a security group for exceptions are more precise in PowerShell. If you prefer the UI, navigate to Mail flow > Rules and recreate the same conditions manually.
What happens to existing forwards that were set up before the rule?
Existing automatic forwards are evaluated on each message flow. As soon as the rule is active, any message that matches the conditions will be blocked, regardless of when the forward was originally configured.