Skip to content
iBlockSpam
Running email day to day

Which Microsoft 365 mail flow rules improve email security, and how do you set them up safely?

By iBlockSpam Team How we check our guides Updated 11 min read 8 sources
Short answer

Use mail flow rules for narrow jobs: tracking or blocking external auto-forwarding, warning on risky external mail, and catching executable attachments. Turn off external forwarding in the outbound spam policy first, use the anti-malware common attachments filter for file types, test each rule in audit mode, and never add an SCL -1 rule scoped only by sender domain.

Mail flow rules, also called transport rules, let you inspect every message passing through Exchange Online and act on it: reject it, tag it, redirect it, quarantine it or add text. That power cuts both ways. A good rule closes a gap Microsoft's built-in policies leave open, and a careless one opens a hole in your spam filter for everyone.

This guide covers the security rules worth having, the built-in settings you should use instead where they exist, the limits and settings that trip people up, and how to test rules before they touch real mail. Menus and limits are as Microsoft documents them at the time of writing (November 2026).

What is a mail flow rule in Microsoft 365?

A mail flow rule is an organization-wide instruction in Exchange Online made of conditions, exceptions and actions, applied to messages in transit. Microsoft describes them as rules that "look for specific conditions on messages that pass through your organization and take action on them" (Microsoft Learn). They differ from Inbox rules, which a single user creates and which act only on that user's mailbox. Attackers abuse Inbox rules; admins own mail flow rules.

Where do you manage mail flow rules?

You manage mail flow rules in the new Exchange admin center (EAC), not the Defender portal:

  • Path: in the EAC at https://admin.exchange.microsoft.com, go to Mail flow > Rules.
  • Direct link: https://admin.exchange.microsoft.com/#/transportrules
  • PowerShell: Get-TransportRule, New-TransportRule, Set-TransportRule, Enable-TransportRule, Disable-TransportRule and Remove-TransportRule in Exchange Online PowerShell.

To create a rule in the EAC, select Add a rule and either pick a template or choose Create a new rule. The wizard has three pages: Set rule conditions, Set rule settings, and Review and finish.

What behaviors catch admins out?

  1. EAC rules start disabled; PowerShell rules don't. Microsoft says rules created in the EAC are disabled "so that you can review the rule one more time." New-TransportRule is the opposite: -Enabled defaults to $true and -Mode defaults to Enforce (New-TransportRule). Every example below sets -Mode Audit for that reason.
  2. Changes aren't instant. A new or modified rule "might take 30 minutes or more" to apply.
  3. Order matters. The rule at the top has priority 0 and runs first. Stop processing more rules prevents later rules from touching the message.
  4. Group membership is cached. Microsoft says rule conditions such as FromMemberOf use a group cache that refreshes about every 3 hours, with no SLA (conditions and exceptions).

What are the mail flow rule limits?

These limits apply to every Microsoft 365 business and enterprise plan (Exchange Online limits):

Limit Value
Transport (mail flow) rules per organization 300
Size of one rule (conditions, exceptions, actions) 8 KB
All words and regular expressions across all rules 20 KB
Recipients added to a message by all rules 100
Recipients in a redirect action (forwardee limit) 10
Times transport rules can redirect one message 1

If rules in two organizations redirect the same message more than once, Microsoft drops it and returns an NDR with 550 5.7.128 TRANSPORT.RULES.RejectMessage; Transport rules loop count exceeded and message rejected.

When should you use a mail flow rule instead of a built-in policy?

Use the built-in control first whenever one exists. Policies are designed for the job, show up in Microsoft's security recommendations, and are harder to get subtly wrong.

Goal Use first Where a mail flow rule fits
Stop external auto-forwarding Outbound spam policy: Automatic forwarding rules set to Off Track forwarding, or block it for specific domains
Block dangerous file types Anti-malware policy: common attachments filter Rules scoped to specific senders or recipients
Show that mail is from outside Native External tag (Set-ExternalInOutlook) A banner on a narrower set of risky messages
Block a sender or domain Tenant Allow/Block List Organization-specific conditions the list can't express
Stop sensitive data leaving by email Purview DLP policy Simple keyword or subject-tag conditions
Let a partner's mail skip filtering Tenant Allow/Block List allow entry, or fix the partner's authentication Only with an authentication condition, never sender domain alone

Microsoft ranks the Tenant Allow/Block List above mail flow rules as a way to allow senders, and calls it "our number one recommended option" (Create allowlists). The sections below go through the other rows.

How do you block automatic forwarding to external addresses?

Block external auto-forwarding with the outbound spam policy first, then use mail flow rules only to track or fine-tune it. Automatic forwarding is a favorite trick after an account takeover: an attacker adds an Inbox rule that quietly copies mail to an outside address. Microsoft notes that users can set up such rules "deliberately or as a result of a compromised account" (Microsoft Learn).

Step 1: Set the outbound spam policy to Off

The outbound spam policy covers both Inbox rules and admin-configured mailbox forwarding. Its Automatic forwarding rules setting has three values:

  • Automatic - System-controlled (the default). It changed to mean Off in 2021 for new organizations and for those not actively using it, but for some older tenants it can still mean On. Microsoft says to pick On or Off explicitly because "the behavior can differ by organization."
  • On - Forwarding is enabled.
  • Off - Forwarding is disabled. Forwarded mail bounces with 5.7.520 Access denied, Your organization does not allow external forwarding. Please contact your administrator for further assistance. AS(7555).

Microsoft's Standard and Strict recommendations are both Off (Microsoft Learn). To set it:

  1. In the Defender portal, go to Email & collaboration > Policies & rules > Threat policies > Anti-spam (https://security.microsoft.com/antispam).
  2. Open Anti-spam outbound policy (Default).
  3. Under Protection settings, set Automatic forwarding rules to Off - Forwarding is disabled and save.

Or in PowerShell:

Set-HostedOutboundSpamFilterPolicy -Identity Default `
    -AutoForwardingMode Off

Forwarding between internal users isn't affected. If someone genuinely needs external forwarding, create a custom outbound spam policy set to On that applies only to them. Our outbound spam policy guide covers custom policies, and the 550 5.7.520 page explains the bounce users see.

Step 2: Know how the controls combine

Microsoft offers two other places to restrict forwarding: remote domains (Set-RemoteDomain -AutoForwardEnabled $false) and mail flow rules. Its rule is that "the block typically wins." If the outbound spam policy is On but a remote domain or a mail flow rule blocks forwarding, the forwarded mail is blocked. That lets you leave the policy On and use remote domains to control which external domains people can forward to.

Step 3: Add a mail flow rule only for what's left

A rule using the message type Auto-forward can reject forwarded mail to outside recipients:

New-TransportRule -Name "Block external auto-forward (Inbox rules)" `
    -MessageTypeMatches AutoForward `
    -SentToScope NotInOrganization `
    -RejectMessageReasonText "External forwarding is not allowed. Contact IT." `
    -Mode Audit

Know its blind spot. Microsoft says that if a message is forwarded with mailbox forwarding (SMTP forwarding), this condition "will not" match (conditions and exceptions). That's why the outbound spam policy comes first.

How do you find who is forwarding today?

Use the Auto forwarded messages report in the EAC for cloud mailboxes. For forwarding from on-premises mailboxes through Microsoft 365, Microsoft suggests a tracking rule: condition The message headers > matches these text patterns, header X-MS-Exchange-Inbox-Rules-Loop, pattern .; action set a message header such as X-Forwarded: True; and a severity of Low, Medium or High so matches appear in the Exchange transport rule report. If you find forwarding you didn't approve, treat it as a possible compromise and follow our guide to malicious inbox rules and auto-forwarding.

How do you add a warning banner to risky external email?

Turn on Microsoft's native External tag first, and keep banner rules for narrower cases. The tag shows an External label near the subject line in Outlook, Outlook for Mac, Outlook on the web and Outlook mobile without editing the message:

Set-ExternalInOutlook -Enabled $true

Microsoft says it can take 24 to 48 hours for users to see the label, and the exception list (-AllowList) holds at most 200 entries. If you already tag external subjects with a mail flow rule, Microsoft says to disable that rule before you enable the native tag, "to avoid duplication" (Set-ExternalInOutlook). Our guide to the Outlook external email warning tag compares the tag with banners.

A banner rule earns its place for targeted warnings, such as external mail whose display name matches one of your executives:

New-TransportRule -Name "Warn: external sender using staff name" `
    -FromScope NotInOrganization `
    -HeaderContainsMessageHeader "From" `
    -HeaderContainsWords "Jane Example","John Example" `
    -ApplyHtmlDisclaimerLocation Prepend `
    -ApplyHtmlDisclaimerText "<p style='background:#fff4ce;padding:8px'><b>Caution:</b> this message is from outside the company but uses a staff member's name.</p>" `
    -ApplyHtmlDisclaimerFallbackAction Ignore `
    -Mode Audit

Points to get right:

  • The fallback action. If the banner can't be added, for example to a signed or encrypted message, the default Wrap creates a new message with the original attached. Microsoft says not to use Wrap in rules that affect incoming external mail because it interferes "with Safe Attachments scanning," and suggests Reject instead (New-TransportRule). Ignore delivers the original without the banner. Choose deliberately: Reject bounces some legitimate signed mail.
  • Subject tags. -PrependSubject "[EXTERNAL] " is an alternative. Add a The subject includes exception so replies don't collect repeated tags.
  • Banner fatigue. If every external message carries a loud banner, people stop reading it. For executive impersonation, pair the banner with the protections in executive and VIP email protection.

How do you block dangerous attachments in Microsoft 365?

Block dangerous file types with the common attachments filter in the anti-malware policy, at Email & collaboration > Policies & rules > Threat policies > Anti-malware (https://security.microsoft.com/antimalwarev2). Its default list includes exe, dll, iso, img, lnk, hta, scr, vbs, docm, msi, jar and others. Microsoft says it uses "best effort true type matching," so an exe renamed to txt is still caught, with extension matching as the fallback (Microsoft Learn). The default action is Reject the message with a non-delivery report (NDR); the other choice is quarantine. Outlook keeps its own client-side list too, covered in Outlook blocked access to potentially unsafe attachments.

Microsoft says the filter is on by default in new anti-malware policies and in the default policy of organizations created after December 1, 2023 (recommended settings). Older tenants should check:

Get-MalwareFilterPolicy | Format-List Name, EnableFileFilter, FileTypeAction

Mail flow rules add attachment conditions that are useful alongside the filter:

  • Any attachment has executable content (AttachmentHasExecutableContent) inspects the file's properties rather than its extension.
  • Any attachment's file extension matches (AttachmentExtensionMatchesWords) also checks files nested inside other attachments.
  • Any attachment is password protected (AttachmentIsPasswordProtected) catches Office files, .zip, .7z and PDFs that scanners can't open, a common way to smuggle malware.

For example, to send executable attachments from outside to quarantine instead of bouncing them:

New-TransportRule -Name "Quarantine external executables" `
    -FromScope NotInOrganization `
    -AttachmentHasExecutableContent $true `
    -Quarantine $true `
    -SetAuditSeverity Medium `
    -Mode Audit

Microsoft notes that when the quarantine action runs, rule evaluation stops, and "the remaining rules in the list aren't evaluated" even after release. Place quarantine rules low in the list. Our guide to dangerous email attachment types explains which formats attackers favor, and email attachment size limits covers the size side.

Which mail flow rules should you avoid?

Avoid any rule that sets the spam confidence level to -1 (Bypass spam filtering) on broad conditions. Microsoft's troubleshooting guide lists "SCL -1 mail flow rule delivers spam to Inbox" as a known problem, caused by a rule scoped to "all messages from a specific domain or IP range, or all messages routed through a connector" (Microsoft Learn). Messages that match show SFV:SKN in the X-Forefront-Antispam-Report header.

Three facts about SCL -1:

  • It's never safe on sender domain alone. Microsoft says never to configure a bypass rule with "only the sender domain as the condition," and not to use your own accepted domains or popular domains, because attackers can spoof them. If a bypass is truly needed, add an Authentication-Results header condition containing dmarc=pass or dmarc=bestguesspass (Create allowlists).
  • It doesn't skip malware or high confidence phishing. Microsoft says SCL -1 "overrides spam filtering only." Those verdicts are still quarantined.
  • There's usually a better fix. If the rule exists because mail first passes through another filtering service, Microsoft's resolution is to configure Enhanced Filtering for Connectors and remove the SCL -1 rule. See using a third-party spam filter with Microsoft 365.

To list every rule that sets an SCL, run Microsoft's diagnostic command:

Get-TransportRule | Where-Object {$_.SetSCL -ne $null} |
    Format-Table Name, State, SetSCL, Priority

Also avoid:

  • Silent deletes. Delete the message without notifying anyone (-DeleteMessage) drops mail without an NDR. Quarantine is easier to recover from.
  • Trusting the IP condition too far. Microsoft says the SenderIPRanges IP is the last hop before Microsoft 365 and "is not guaranteed to be the original sender's IP address."
  • Duplicating policy settings. A rule and a policy that disagree are hard to debug months later. Use the Comments field to record why every rule exists.

Our guide on why spam gets through Microsoft 365 shows how to spot these rules from a message's headers.

How do you test a mail flow rule before enforcing it?

Test a mail flow rule by creating it in a test mode, confirming matches in reports and message trace, then switching it to Enforce. Microsoft's own tip is to "thoroughly test each rule and interactions between rules."

Setting EAC name PowerShell Use it for
Enforce Enforce -Mode Enforce (default) Live rules
Test, no notices Test without Policy Tips -Mode Audit Logging what would happen
Test with notices Test with Policy Tips -Mode AuditAndNotify Testing sender notifications
Severity Severity (Low, Medium, High) -SetAuditSeverity Making matches show in reports
Sender address check Match sender address in message -SenderAddressLocation Header (default), Envelope, or both
  1. Create the rule in test mode (-Mode Audit, or Test without Policy Tips in the EAC).
  2. Set a severity. Any value other than Not audit makes matches appear in the Exchange Transport Rule report under Reports > Mail flow. Microsoft says most data appears within 24 hours, but some can take up to 5 days.
  3. Wait at least 30 minutes, then send test messages. Run a message trace to confirm the rule matched.
  4. Check the headers of a test message in our Email Header Analyzer. Our guide to Microsoft 365 spam headers explains the fields.
  5. Enforce:
Set-TransportRule -Identity "Quarantine external executables" `
    -Mode Enforce
  1. Back up your rules before larger changes. Export-TransportRuleCollection returns the data, which you then write to a file:
$file = Export-TransportRuleCollection
[System.IO.File]::WriteAllBytes('C:\Backup\Rules.xml', $file.FileData)

Microsoft says Import-TransportRuleCollection "will be deprecated" in Exchange Online and documents a script-based restore instead, so keep exports, comments and a written list of your rules.

Next steps

  1. Set Automatic forwarding rules to Off in the outbound spam policy, with custom policies for approved exceptions.
  2. Turn on the native External tag with Set-ExternalInOutlook -Enabled $true, and retire old subject-tagging rules.
  3. Confirm the common attachments filter is on with Get-MalwareFilterPolicy.
  4. List rules with Get-TransportRule | Format-Table Name, State, Priority, Mode, and remove any SCL -1 rule that has no authentication condition.
  5. Add new rules in audit mode, check the report, then enforce.
  6. Run a free Email Health Check to confirm your MX, SPF and DMARC records, and see how to block a sender or domain in Microsoft 365 for blocking without a rule.

If a forwarding rule or bypass turns out to be an attacker's work, move to Microsoft 365 compromised account remediation. If you want inbound filtering in front of Microsoft 365 with its own attachment-type and geographic filters, compare the options in Microsoft 365 built-in filtering vs a gateway. Browse more guides on running email day to day.

Frequently asked questions

Do mail flow rules block mailbox forwarding set by an admin?

Not with the auto-forward message type condition. Microsoft says that condition doesn't match messages sent with mailbox forwarding, also called SMTP forwarding. To stop every kind of automatic external forwarding, set Automatic forwarding rules to Off in the outbound spam policy, which covers Inbox rules and mailbox forwarding alike.

How long does a new mail flow rule take to work?

Microsoft says it might take 30 minutes or more for a new or changed mail flow rule to apply to email. Group membership used in rule conditions is cached and refreshes roughly every three hours. Wait before you test, then use message trace to see which rules a message matched.

How many mail flow rules can a Microsoft 365 tenant have?

At the time of writing (November 2026), Microsoft lists 300 transport rules per organization, 8 KB per individual rule, and 20 KB in total for all words and regular expressions in every rule's conditions and exceptions. A small business rarely gets close, but long keyword lists use up the 20 KB quickly.

Should I block attachments with a mail flow rule or the anti-malware policy?

Start with the common attachments filter in the anti-malware policy. It detects many file types by their content rather than their name, rejects matches with an NDR by default, and is on by default in new policies. Add a mail flow rule only for something the filter can't express, such as a rule scoped to particular senders.

What does audit mode do in a mail flow rule?

In PowerShell, Mode Audit writes the actions a rule would have taken to the message tracking log without changing delivery. AuditAndNotify does the same and also sends notifications. In the Exchange admin center the equivalents are Test without Policy Tips and Test with Policy Tips. Switch to Enforce once results look right.

Are PowerShell-created transport rules enabled straight away?

Yes. New-TransportRule creates rules enabled by default and in Enforce mode by default, unlike the Exchange admin center, which saves new rules as disabled. Add -Mode Audit or -Enabled $false when you create a security rule in PowerShell, so it can't bounce or quarantine real mail before you've checked it.

Sources

  1. Microsoft Learn: Manage mail flow rules in Exchange Online
  2. Microsoft Learn: Mail flow rule conditions and exceptions (predicates) in Exchange Online
  3. Microsoft Learn: New-TransportRule
  4. Microsoft Learn: Control external email forwarding and fix 5.7.520 errors
  5. Microsoft Learn: Troubleshoot anti-spam policies in Microsoft Defender for Office 365
  6. Microsoft Learn: Anti-malware protection for email in Microsoft 365
  7. Microsoft Learn: Set-ExternalInOutlook
  8. Microsoft Learn: Exchange Online limits

See how your domain measures up

Run a free Email Health Check: MX, SPF, DKIM, DMARC and transport security in one scan, with the raw records shown. No sign-up.

Keep reading