Apply Microsoft 365 Do Not Forward Protection Programmatically
Question details
Apply Do Not Forward protection to an Exchange Online email generated or processed programmatically.

- Product
- Microsoft 365 Message Encryption and Exchange Online
- Device & OS
- not provided
- Scenario
- A developer wants to protect an email with Do Not Forward, potentially using C# or Exchange Web Services.
- Observed behavior
- Protect-RMSFile can protect a local file, but the resulting PFILE cannot be uploaded to Exchange Online as a Do Not Forward-protected email.
Confirm that your Microsoft 365 subscription supports Message Encryption and that it is configured for your Exchange Online organization. You also need permission to create mail flow rules in the Exchange admin center.
Apply Do Not Forward with an Exchange Online mail flow rule
Use a mail flow rule to protect messages that match conditions you define, including messages sent by an application.
Do Not Forward is a message-level restriction in Microsoft 365 Message Encryption. Protect-RMSFile applies rights protection to files and does not convert an MSG or PFILE into an Exchange Online message with the same restriction.
Sign in to the Exchange admin center, then go to Mail flow > Rules and choose Add a rule.
Create a rule with conditions that identify the messages to protect, such as the application's sender address and a specific subject phrase. Keep the conditions narrow enough to avoid affecting unrelated mail.
Under the rule actions, choose Modify the message security > Apply Office 365 Message Encryption and rights protection, then select Do Not Forward.
Save and enable the rule, then send a matching test message from the application to a test recipient. Open the message in a supported mail client or the encryption portal and verify that forwarding is restricted.

Work with Office documents in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with Office documents. Its format compatibility makes it easier to move existing files into WPS, but it does not apply or replace Exchange Online Do Not Forward protection.

Frequently Asked Questions
Why can't I use Protect-RMSFile to apply Do Not Forward to an email?
Protect-RMSFile protects files, while Do Not Forward is applied to an Exchange Online message through Microsoft 365 Message Encryption. Protecting a local MSG file does not apply the message-level restriction to an email.
Can a mail flow rule protect email sent by an application?
Yes. In the Exchange admin center, go to Mail flow > Rules and create a rule that matches the application's messages. Set the message security action to apply encryption and rights protection with Do Not Forward.
What does Do Not Forward prevent recipients from doing?
Do Not Forward restricts actions such as forwarding and changing recipients. Other restrictions, including printing or saving, depend on the client and how the protected content is accessed; it cannot prevent someone from capturing the content by other means.
Where can I get help applying protection through C# or an Exchange API?
Consult the current Microsoft developer documentation for your chosen API, or post on Microsoft Q&A with details of your C# application, API, and authentication method. Do not assume that a file-protection API applies message-level restrictions.




