Skip to content

How to Create Mail Flow Rules in Exchange Online

Create mail flow rules (transport rules) in Exchange Online: add disclaimers, route mail, block attachments, and warn on external senders, with EAC and PowerShell steps.

MGMCSA Guru Team September 30, 2026 7 min read
Cover showing the Exchange admin center mail flow rule builder with conditions, actions, and exceptions

Mail flow rules are how you tell Exchange Online to do something to a message based on conditions you set — add a disclaimer, warn on external senders, block a risky attachment type, or route certain mail to a specific connector. If you’ve used Outlook rules, the idea is familiar, but these run on the server for the whole organization, not in one person’s mailbox.

This guide covers building a rule in the Exchange admin center and in PowerShell, the condition/action/exception model that every rule follows, and the practical patterns most tenants actually need. It also covers the part that bites people: rule order and test mode. Get those wrong and a rule either never fires or fires on everything.

How a mail flow rule is built

Every rule is the same three parts. Once this clicks, the portal builder makes sense.

The three parts of every rule

Conditions When the rule applies — e.g. sender is outside the org, subject contains a word
Actions What it does — e.g. prepend a disclaimer, reject, redirect, set a header
Exceptions When to skip it even if the condition matched — e.g. except a trusted domain

A rule with no conditions applies to all mail, which is occasionally what you want and usually not. Exceptions always win over conditions, so they’re your safety valve for the one sender or domain that shouldn’t be caught.

Create a rule in the Exchange admin center

The EAC builder is the right place to start, especially for your first few rules.

  1. Sign in to the Exchange admin center (admin.exchange.microsoft.com).
  2. Go to Mail flow → Rules.
  3. Click Add a rule (+). You can start from a template (like “Apply disclaimers”) or Create a new rule.
  4. Give the rule a clear name — future-you will thank you.
  5. Set Apply this rule if… (the condition), Do the following… (the action), and Except if… (the exception).
  6. Set the rule mode. Start in Test if the rule blocks or redirects mail.
  7. Set the priority, then Save.

Pattern 1: Warn on external senders

This is the most common request — flag mail from outside the organization so users are wary of impersonation. In the EAC, the condition is The sender is located → Outside the organization, and the action is Prepend the disclaimer. In PowerShell:

Connect-ExchangeOnline

New-TransportRule -Name "External sender warning" `
  -FromScope NotInOrganization `
  -SentToScope InOrganization `
  -ApplyHtmlDisclaimerLocation Prepend `
  -ApplyHtmlDisclaimerText "<div style='background:#fff3cd;padding:8px;border:1px solid #ffe69c;'><b>CAUTION:</b> This email came from outside your organization. Don't click links or open attachments unless you recognize the sender.</div>" `
  -ApplyHtmlDisclaimerFallbackAction Wrap

To avoid stacking the banner on every reply in a thread, add an exception so the rule skips messages that already contain the warning text. The cleaner long-term approach is the native external sender tag in Outlook, but the rule above works everywhere and gives you full control over the wording.

Pattern 2: Block risky attachment types

To stop executable and script attachments at the gateway, match on attachment file type and reject the message. In the EAC: condition Any attachment → file extension matches, action Block the message → reject and return a message. In PowerShell:

New-TransportRule -Name "Block executable and script attachments" `
  -AttachmentExtensionMatchesWords @("exe","js","vbs","scr","bat","cmd","jar","ps1") `
  -RejectMessageReasonText "This attachment type is blocked by company policy. Contact IT if you need to receive this file." `
  -RejectMessageEnhancedStatusCode "5.7.1"

This handles routing and policy, not malware scanning. Keep it alongside Defender for Office 365 — see Safe Links vs Safe Attachments for the scanning side, which catches threats a static extension block never will.

Pattern 3: Add a company disclaimer

A standard footer on outbound mail is a classic disclaimer rule: condition sender is inside the organization, action prepend or append a disclaimer.

New-TransportRule -Name "Company footer" `
  -FromScope InOrganization `
  -SentToScope NotInOrganization `
  -ApplyHtmlDisclaimerLocation Append `
  -ApplyHtmlDisclaimerText "<hr><p style='font-size:11px;color:#666;'>Contoso Ltd. This message is confidential and intended only for the named recipient.</p>" `
  -ApplyHtmlDisclaimerFallbackAction Wrap

The FallbackAction matters: Wrap keeps the original message intact if the disclaimer can’t be applied (for example, on signed or encrypted mail), instead of dropping it.

Rule order and the “stop processing” trap

Rules run top to bottom by priority — the lowest number first. By default, processing continues to the next rule after a match. That’s fine until two rules collide.

Rule order behavior

Priority Lower number runs first (0 is first)
After a match Next rule still runs unless you stop it
Stop processing more rules An action that makes the current rule the last one to apply
Exceptions Always override conditions on the same rule

If a broad “block this domain” rule sits below a “redirect for review” rule, mail might get redirected and blocked, or one might never fire. Order rules deliberately, and add Stop processing more rules when a match should be the final word.

Before you flip a rule on

A short pre-flight check saves cleanup later.

Before enabling a mail flow rule

  • The rule has a clear, descriptive name
  • Conditions are specific enough not to catch unintended mail
  • Exceptions cover the senders/domains that must not be affected
  • Priority is set so it runs in the right order with existing rules
  • Blocking/redirecting rules start in test mode
  • You know how you'll verify it (message trace)

After it’s live, confirm it’s behaving with message trace in Exchange Online, which shows whether a rule acted on a given message and why. If a rule is the reason mail isn’t arriving, the broader checklist in Microsoft 365 email not sending or receiving helps you separate a rule problem from a mail flow or DNS one.

Manage rules with PowerShell

For auditing or bulk changes, PowerShell beats clicking through the portal. A few useful commands:

# List all rules with priority and state
Get-TransportRule | Format-Table Name, Priority, State, Mode -AutoSize

# Disable a rule without deleting it
Disable-TransportRule -Identity "Block executable and script attachments"

# Change a rule's priority (0 runs first)
Set-TransportRule -Identity "External sender warning" -Priority 0

# Export all rules to a file for backup
Get-TransportRule | Export-Clixml C:\Temp\transport-rules-backup.xml

Export your rules before making big changes. Rebuilding a complex rule set from memory is no fun.

Wrapping up

Mail flow rules follow one model: conditions, actions, exceptions, in priority order. Build the common ones — external warnings, attachment blocks, disclaimers — in the EAC or with New-TransportRule, and lean on test mode before enforcing anything that blocks or redirects. Watch rule order and use “stop processing” when a match should be final. They’re powerful for routing and custom handling, but they sit alongside your anti-spam and anti-phishing protection, not in place of it.

Frequently asked questions

What's the difference between a mail flow rule and a transport rule?

They're the same thing. 'Mail flow rule' is the name used in the Exchange admin center, and 'transport rule' is the older term still used in PowerShell cmdlets like New-TransportRule. If a doc says transport rule and the portal says mail flow rule, they mean the same feature.

In what order do mail flow rules run?

Rules run top to bottom by priority, lowest number first. By default a later rule still processes after an earlier one unless you stop it. Use the 'Stop processing more rules' action when a match should be final, and order your rules so broad blocks or routing happen where you intend.

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

New and changed rules usually take effect within a few minutes, but full propagation across the service can take up to an hour. Don't assume a rule is broken if it doesn't fire on the first test message; wait a little and test again.

Can I test a mail flow rule before it affects real mail?

Yes. Set the rule mode to test, optionally with policy tips, so it logs what it would have done without acting on messages. Review the results, then switch it to enforce. This is the safe way to validate a block or routing rule before it touches production mail.

Why isn't my external sender warning showing on some emails?

Common reasons are that the rule already ran once and added the prefix, an exception is matching, or the message came from a domain on your allow or internal list. Also, prepending HTML disclaimers can render oddly in some clients. Check the rule's conditions, exceptions, and whether a higher-priority rule stopped processing.

Do mail flow rules replace anti-spam and anti-phishing policies?

No. Mail flow rules handle routing and custom handling; they aren't a substitute for Exchange Online Protection and Defender policies. Use them alongside anti-phishing, Safe Links, and Safe Attachments, not instead of them.

Sources & further reading

Official vendor documentation referenced while writing this guide.

MG

MCSA Guru Team

IT & Systems Administration

We are working IT pros and system administrators who spend our days in Windows Server, Microsoft 365, and the wider Microsoft stack. MCSA Guru is where we write down the fixes and walkthroughs we wish we had found the first time.

MCSA Guru provides independent, educational IT guidance. Microsoft, Windows, Windows Server, Microsoft 365, Exchange, and Microsoft Teams are trademarks of Microsoft Corporation; Docker is a trademark of Docker, Inc. MCSA Guru is not affiliated with or endorsed by Microsoft or Docker. Always test changes in a safe environment before applying them in production.

Related guides

Fixing something right now?

Jump straight into the guide library or search for the exact error or task you are dealing with.