Prevent Exchange Online From Removing a Custom Email Header
Question details
Determine why a custom email header is missing or changed and whether an Exchange Online mail flow rule can add the required header.

- Product
- Microsoft 365 Exchange Online
- Device & OS
- not provided
- Scenario
- An application sends messages with a custom header containing XML or application-specific data through Exchange Online.
- Observed behavior
- The custom header or its contents may be changed or missing in the received message.
Have a controlled test message, the expected header name and value, and access to its complete headers before and after delivery. To create a rule, you also need an Exchange Online role with permission to manage mail flow rules.
Add the Required Header With an Exchange Online Mail Flow Rule
Use this approach when a known header value can be added to matching messages during Exchange Online transport.
A mail flow rule can set a specified header value, but it does not guarantee preservation of every third-party header. In particular, setting a fixed value cannot recover a dynamic value that was already removed.
Open the complete headers for the test message before and after delivery. Compare the custom header name and value to identify where they differ; include any intermediate gateway logs or headers available.
In the Exchange admin center, go to Mail flow > Rules, select Add a rule, and choose Create a new rule.
Name the rule and select conditions that limit it to your test messages, such as the sender. Under Do the following, choose Modify the message properties > Set a message header, then enter the required header name and a suitable fixed value.
Complete the rule settings, save and enable the rule, then send a controlled test message. Open the delivered message's complete headers and check whether the expected header and value are present.

Trace a Dynamic Header Through the Delivery Path
Use this approach when the application generates a different header value for each message or the header is still missing after a rule is applied.
Work With Office Files in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Microsoft Office formats, making it easier to move everyday document work. It does not change Exchange Online mail flow or fix email header removal.

Frequently Asked Questions
Can a mail flow rule preserve the original value of every custom header?
No. A rule can set a specified header value on matching messages, but it cannot necessarily recover a dynamic value that was removed before the rule ran. Test the complete delivery path.
Where do I create an Exchange Online header rule?
In the Exchange admin center, go to Mail flow > Rules > Add a rule > Create a new rule. Under Do the following, select Modify the message properties > Set a message header.
Why is the header still missing after I add a rule?
The rule may not match the test message, may not be enabled, or a later gateway or recipient system may remove the header. Check the rule conditions and compare headers and logs at available points along the delivery path.
Can I put XML directly in a custom email header?
Header values must comply with email header formatting and size requirements, and transport systems may modify or reject unsuitable values. Consider sending complex XML in the message body or an attachment instead.




