Working with Rules On Exchange Server
Managing Rules
Aspose.Email for .NET can be used to manage the rules on Exchange Server using the EWSClient class. This class uses Exchange Web Services (EWS), which are available in Exchange Server 2007 and later releases. This article explains how to manage the rules:
- Read the rules already on the server.
- Create a new rule.
- Update an existing rule.
Microsoft Exchange Server 2010 Service Pack 1 is required for all features described in this article.
Read Rules
To get all the rules from the Exchange Server:
- Connect to an Exchange Server using the IEWSClient class.
- Call the IEWSClient.GetInboxRules() method to get all the rules.
- In a foreach loop, browse through all the rules and display the rule properties like conditions, actions, and name.
The following code snippet shows you how to read rules.
Creating a New Rule
To create a new rule on the Exchange Server, perform the following steps:
- Connect to an Exchange Server using the IEWSClient interface.
- Create a new instance of the InboxRule class and set the following mandatory properties:
- DisplayName
- Conditions
- Actions
- Call the IEWSClient.CreateInboxRule() method to create the rule.
The following code snippet shows you how to create a new rule.
Updating a Rule
To update a rule on the Exchange Server:
- Connect to an Exchange Server using the IEWSClient class.
- Call the IEWSClient.GetInboxRules() method to get all the rules.
- In a foreach loop, browse through all the rules and get the rule you want to change by matching the DisplayName in a condition.
- Update the rule properties.
- Call the IEWSClient.UpdateInboxRule() method to update the rule.
The following code snippet shows you how to update a rule.