Working with Rules On Exchange Server
Managing Rules
Aspose.Email 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. To show how to manage rules, this article explains how to:
- 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 loop, browse through all the rules and display the rule properties like conditions, actions, and names.
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 class.
- 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 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.