Getting Inbox rules by using the EWS Managed API 2.0

You can use the Microsoft Exchange Web Services (EWS) Managed API to get all existing Inbox rules.

Last modified: October 13, 2012

Applies to: EWS Managed APIĀ | Exchange Server 2010 Service Pack 1 (SP1)

Note: This content applies to the EWS Managed API 2.0 and earlier versions. For the latest information about the EWS Managed API, see Web services in Exchange.

To get Inbox rules

  • Create a RuleCollection object that represents the rules for the authorized user by calling the GetInboxRules method to retrieve a collection of all server rules for the user. You must provide it with connection configuration information by using an ExchangeService object named service, as shown in the following example.

    RuleCollection ruleCollection = service.GetInboxRules("");


The following code example shows how to get the Inbox rules for a user and to display the count and display name of each rule.

// Get the Inbox rules collection and display the count of the rules.
RuleCollection ruleCollection = service.GetInboxRules("");
Console.WriteLine("Collection count: " + ruleCollection.Count);
// Write the DisplayName and Id of each rule.
foreach (Rule rule in ruleCollection)

The following example shows the XML request that is sent by the GetInboxRules method.

<soap:Envelope xmlns:xsi="" 
    <t:RequestServerVersion Version="Exchange2010_SP1" />

The following example shows the XML response that is returned by using the GetInboxRules method. In this example, there are two rules for the specified user.


The Id attribute was shortened to preserve readability.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="">
    <h:ServerVersionInfo MajorVersion="14" 
        xmlns:xsd="" />
  <s:Body xmlns:xsi="" 
    <GetInboxRulesResponse ResponseClass="Success" 
        <Rule xmlns="">
              <String>This is Junk</String>
              <FolderId ChangeKey="AQAAAA==" Id="AAMkADc4ODY2Z" />
        <Rule xmlns="">
              <FolderId ChangeKey="AQAAAA==" Id="AAMkADc4ODY2Z" />

This example assumes that the ExchangeService object is configured correctly to connect to the user's Client Access server.

The GetInboxRules method returns a RulesCollection object, with one Rule object for each rule in the collection.

Compiling the code

For information about compiling this code, see Getting started with the EWS Managed API 2.0.

Robust programming

  • Write appropriate error handling code for common search errors.

  • Review the client request XML that is sent to the Exchange server.

  • Review the server response XML that is sent from the Exchange server.

  • Set the service binding as shown in Setting the Exchange service URL by using the EWS Managed API 2.0. Do not hard code URLs because if mailboxes move, they might be serviced by a different Client Access server. If the client cannot connect to the service, retry setting the binding by using the AutodiscoverUrl(String) method.

  • Set the target Exchange Web Services schema version by setting the requestedServerVersion parameter of the ExchangeService constructor. For more information, see Versioning EWS requests by using the EWS Managed API 2.0.


  • Use HTTP with SSL for all communication between client and server.

  • Always validate the server certificate that is used for establishing the SSL connections. For more information, see Validating X509 certificates by using the EWS Managed API 2.0.

  • Do not include user names and passwords in trace files.

  • Verify that Autodiscover lookups that use HTTP GET to find an endpoint always prompt for user confirmation; otherwise, they should be blocked.