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:

  1. Connect to an Exchange Server using the IEWSClient class.
  2. Call the IEWSClient.GetInboxRules() method to get all the rules.
  3. 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:

  1. Connect to an Exchange Server using the IEWSClient interface.
  2. Create a new instance of the InboxRule class and set the following mandatory properties:
    1. DisplayName
    2. Conditions
    3. Actions
  3. 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:

  1. Connect to an Exchange Server using the IEWSClient class.
  2. Call the IEWSClient.GetInboxRules() method to get all the rules.
  3. In a foreach loop, browse through all the rules and get the rule you want to change by matching the DisplayName in a condition.
  4. Update the rule properties.
  5. Call the IEWSClient.UpdateInboxRule() method to update the rule.

The following code snippet shows you how to update a rule.