Exchange ServerTroubleshooting

Exchange Server transport rules not applying: priorities, conditions and how to test

A mail flow rule that should fire does nothing, or fires on the wrong mail? Check state, mode, priority and conditions, then prove the match with message tracking.

You create a mail flow rule (transport rule) in Exchange Server to add a disclaimer, tag external mail or block an attachment, and nothing happens. Or it fires on mail it was never meant to touch. Rules fail quietly, so in this post I'll walk through the checks that find the cause: state and mode, priority and stop processing, how each condition really matches, and how to prove a match with message tracking.

Errors this guide fixes

  • 5.7.1 Delivery not authorized, message refusedNDR (rule rejection, default text)
How this guide is organized: Symptoms → Why it happens → How to fix it → Verify the fix → Key takeawaysFlow diagram of the article's sections in reading order: 1. Symptoms. 2. Why it happens. 3. How to fix it. 4. Verify the fix. 5. Key takeaways. Toolbox: Event ID 4002, Event ID 16028, Export-TransportRuleCollection, Import-TransportRuleCollection, Restart-Service.1Symptoms2Why it happens3How to fix it4Verify the fix5Key takeawaysTOOLBOXEvent ID 4002Event ID 16028Export-TransportRuleCollectionImport-TransportRuleCollectionRestart-ServiceHow this guide is organized: Symptoms → Why it happens → How to fix it → Verify the fix → Key takeawaysFlow diagram of the article's sections in reading order: 1. Symptoms. 2. Why it happens. 3. How to fix it. 4. Verify the fix. 5. Key takeaways. Toolbox: Event ID 4002, Event ID 16028, Export-TransportRuleCollection, Import-TransportRuleCollection, Restart-Service.1Symptoms2Why it happens3How to fix it4Verify the fix5Key takeawaysTOOLBOXEvent ID 4002Event ID 16028Export-TransportRuleCollectionImport-TransportRuleCollectionRestart-Service
At a glance: how this guide is organized · 5 sections · 5 key tools

Symptoms#

  • The rule's action never shows up: no disclaimer, no subject prefix, no Bcc copy, no rejection.
  • It works for some senders or recipients but not others, for example mail sent to an alias.
  • It stopped working after another rule was added or reordered.
  • A message is rejected that shouldn't be, and the NDR shows the text Exchange uses when a rule rejects mail without a custom explanation:
Text
5.7.1 Delivery not authorized, message refused

5.7.1 is the default enhanced status code for a rule rejection. If you see it, a rule is applying, just to the wrong messages.

Why it happens#

Why an Exchange mail flow rule doesn't fireIs the rule enabled, set to Enforce and inside its date window? if No: Enable it and set Mode to Enforce (A rule in a test mode looks like it isn't working.); if Yes: Does the message pass through servers that hold the rule? if No: Create the rule where the mail flows (On every Edge server, and in Exchange Online for mail that skips on-premises.); if Yes: Does a higher rule with Stop processing match the message? if Yes: Move your rule up or narrow the other (Priority 0 runs first, and stop processing ends the evaluation.); if No: Recheck conditions and sender location (AND between conditions, OR between values, any exception wins; try HeaderOrEnvelope.)Is the rule enabled, set toEnforce and inside its datewindow?FIXEnable it and set Modeto EnforceA rule in a test mode lookslike it isn't working.NoDoes the message pass throughservers that hold the rule?FIXCreate the rule wherethe mail flowsOn every Edge server, andin Exchange Online for mailthat skips on-premises.NoDoes a higher rule with Stopprocessing match themessage?FIXMove your rule up ornarrow the otherPriority 0 runs first, andstop processing ends theevaluation.YesFIXRecheck conditionsand sender locationAND between conditions,OR between values, anyexception wins; tryHeaderOrEnvelope.NoYesYesWhy an Exchange mail flow rule doesn't fireIs the rule enabled, set to Enforce and inside its date window? if No: Enable it and set Mode to Enforce (A rule in a test mode looks like it isn't working.); if Yes: Does the message pass through servers that hold the rule? if No: Create the rule where the mail flows (On every Edge server, and in Exchange Online for mail that skips on-premises.); if Yes: Does a higher rule with Stop processing match the message? if Yes: Move your rule up or narrow the other (Priority 0 runs first, and stop processing ends the evaluation.); if No: Recheck conditions and sender location (AND between conditions, OR between values, any exception wins; try HeaderOrEnvelope.)Is the rule enabled, set to Enforce and inside itsdate window?NoFIXEnable it and set Mode to EnforceA rule in a test mode looks like it isn't working.YesDoes the message pass through serversthat hold the rule?NoFIXCreate the rule where the mail flowsOn every Edge server, and in Exchange Online formail that skips on-premises.YesDoes a higher rule with Stop processingmatch the message?YesFIXMove your rule up or narrow the otherPriority 0 runs first, and stop processingends the evaluation.NoFIXRecheck conditions and senderlocationAND between conditions, OR betweenvalues, any exception wins; tryHeaderOrEnvelope.
Figure 1 · Decision tree Why an Exchange mail flow rule doesn't fire. Answer from the top. After any change, allow for AD replication and the four-hour group cache before you test again.

On Mailbox servers, rules are applied in transit by the Transport Rule agent; Edge Transport servers use the Edge Rule agent. Rules act on messages while they move through the transport pipeline, never on items already sitting in a mailbox. The usual causes:

  • State, mode or dates. The rule is disabled, still in a test mode (Audit or AuditAndNotify, shown in the Exchange admin center as Test without Policy Tips and Test with Policy Tips), or outside its ActivationDate/ExpiryDate window.
  • Priority and stop processing. Rules run in priority order, and 0 is the highest. A higher rule that matches the same message and has Stop processing more rules set ends the evaluation. Some actions, such as deleting the message without notifying anyone, also stop later rules.
  • Condition logic. Multiple conditions are combined with AND. Multiple values inside one condition are OR. Any single exception cancels the actions.
  • Header vs envelope. Sender conditions look at the message header by default (SenderAddressLocation = Header), not the SMTP envelope. The To/Cc header conditions and the recipient-address word and pattern conditions match only the recipient's primary address, so mail sent to a proxy address slips past.
  • Content that can't be read. For S/MIME-encrypted messages a rule sees only the envelope headers. Rights-protected messages need transport decryption before content conditions work. Attachment pattern matching scans only the first 150 KB of each attachment.
  • Directory data. Conditions based on Active Directory properties work only for senders and recipients inside the organization. Group membership comes from a cache that expires every four hours by default, so a user you just added to a group isn't matched yet.
  • Where the rule lives. Mailbox server rules are stored in Active Directory and need domain controller replication. Edge Transport rules are stored per server in AD LDS and aren't replicated. In hybrid, on-premises rules are never copied to Exchange Online.
  • Errors during evaluation. With the default RuleErrorAction of Ignore, a rule that can't finish processing a message is skipped silently.

How to fix it#

  1. Read the rule list in priority order. In the Exchange Management Shell:
    PowerShell
    Get-TransportRule | Sort-Object Priority |
        Format-Table Priority, Name, State, Mode, StopRuleProcessing -AutoSize
    
    Get-TransportRule "Tag external mail" |
        Format-List Name, State, Mode, Priority, ActivationDate, ExpiryDate, RuleErrorAction, SenderAddressLocation, Description
    The Description property spells out the conditions, exceptions and actions in plain words. Read it the way Exchange does: every condition must match, any exception wins.
  2. Enable and enforce it.
    PowerShell
    Enable-TransportRule "Tag external mail"
    Set-TransportRule "Tag external mail" -Mode Enforce
  3. Fix the order. Look above your rule for any rule with StopRuleProcessing set to True whose conditions could also match the same message. Either move your rule above it, or narrow the other rule:
    PowerShell
    Set-TransportRule "Tag external mail" -Priority 0
  4. Match what the sender really uses. If a gateway, application or relay sets a different envelope sender than the From header, make the rule check both:
    PowerShell
    Set-TransportRule "Block finance spoof" -SenderAddressLocation HeaderOrEnvelope
    For recipients, make sure the address in the condition is the primary SMTP address, or match on the recipient object or a group instead of typed text.
  5. Allow for caches and replication. After changing a rule, give Active Directory replication time to finish. For group-based conditions, either wait for the expanded groups cache to refresh or restart the Transport service on each Mailbox server that has to see the change straight away (Restart-Service MSExchangeTransport), ideally after hours.
  6. Put the rule where the mail flows. On Edge Transport servers, create the rule on every Edge server, or use Export-TransportRuleCollection and Import-TransportRuleCollection. Note that importing a collection replaces the rules already on the target, so export them first. In hybrid, create a matching rule in Exchange Online for mail that never passes through your on-premises servers, and check that every condition and action you need exists there.
  7. Handle protected content. For rights-protected mail, check Get-IRMConfiguration | Format-List TransportDecryptionSetting. Content conditions can't work on S/MIME-encrypted messages at all, so base those rules on sender, recipient or header conditions instead.

Verify the fix#

Test safely first: set a new rule to Audit mode and add a Generate incident report and send it to action, so you get a report for every match without changing delivery. Then send a test message with a unique subject and read the agent data that message tracking recorded for it on all transport servers:

PowerShell
$rule = Get-TransportRule "Tag external mail"
$hits = Get-TransportService | ForEach-Object {
    Get-MessageTrackingLog -Server $_.Name -EventId AGENTINFO -MessageSubject "Rule test 01" `
        -Start (Get-Date).AddHours(-1) -ResultSize Unlimited
}
$hits | Select-Object Timestamp, Source, @{n='AgentData';e={$_.EventData | Out-String}} | Format-List
$hits | Where-Object { ($_.EventData | Out-String) -match $rule.Guid }   # entries that name your rule
  • Good: the transport rule agent's AGENTINFO data for the test message references your rule's GUID, and the action is visible in the delivered message.
  • Rule not referenced: it didn't match. Recheck conditions, exceptions and the header/envelope setting.
  • Listed, but no visible change: the rule is still in a test mode, or a later rule changed the result.
  • After any change: each Mailbox server logs Event ID 4002 in the Application log when its Transport service picks up a modified rule (Event ID 16028 on Edge Transport servers).

For reading tracking results in depth, see Message tracking on Exchange Server. To check the headers a rule added, see Reading email headers in Exchange Server.

Key takeaways#

  • Check state, mode and dates before anything else; a rule in a test mode looks like it isn't working.
  • Keep a documented rule order: rejections first, with stop processing, then tagging and disclaimers.
  • Remember AND between conditions, OR between values, and that one exception beats everything.
  • Use HeaderOrEnvelope when relays and applications send on behalf of other addresses.
  • Rules run only where the message passes through transport: plan for Edge servers and Exchange Online separately. For cloud-side rule design, see Mail flow rules that don't backfire.

References#

Written and checked against current Microsoft Learn documentation. Test changes with a pilot group before rolling them out to everyone, and if an admin center path has moved since, search for the setting name instead.

Spotted a mistake, or did this fix work differently for you? Email me or message me on LinkedIn — corrections are credited in the article.

Written by

Omer Eltayeb

M365 Subject Matter Expert, former Microsoft Cloud Solutions Architect, Microsoft Certified Trainer and Microsoft Innovative Educator Expert (2024–26) and Microsoft Elevate Educator Expert (2026–27). I share practical, step-by-step guides, study plans, scripts and toolkits for Microsoft Intune, Configuration Manager, Microsoft Entra ID, Microsoft Defender, Exchange and Microsoft 365 with the community.

Microsoft Certified Trainer (MCT) 2026Microsoft Innovative Educator Expert 2025–2026Microsoft Elevate Educator Expert 2026–2027ISC2 Certified Information Systems Security Professional (CISSP)Microsoft 365 Certified: Enterprise Administrator Expert (MS-102)