Platform SDK: Exchange Server

Rules CoClass

The Rules COM class is an ordered collection that defines an object with methods and properties that you can use to access, create, and delete folder Rule objects.

CLSID
92C2FEE7-00A6-11D2-BC07-00C04F8C92F7
ProgID
MSExchange.Rules
Type Library
Microsoft Exchange 5.5 Rules Type Library 1.0 (Rule.dll)
Threading Model
Single-threaded apartment (STA)
Interfaces
The Rules class exposes the IRules dual interface.

Remarks

The Rules object is an ordered collection of Rule objects defined for a particular Exchange folder. You specify for which folder you want to define rules by setting the IRules::Folder property to a corresponding CDO.Folder object. For example, to define rules for the Inbox folder for the TestUser account on the Microsoft Exchange server SERVER, perform the following steps:

Set mySession   = CreateObject("MAPI.Session")
mySession.Logon   "","",False,True,True,True,"SERVER" & vbLF & "TestUser"

Set myRules     = CreateObject("MSExchange.Rules")
Set myRules.Folder  = mySession.Inbox
 

The Rules collection then contains the Rule objects representing the rules on that folder as found in the information store. You can then create new rules or modify or delete old rules. You can also change the order in which rules are applied by rearranging their order in the collection.

To save the rule changes to the information store, call the IRules::Update method.

Note  You can only create (IRules::Add) and remove (IRules::Delete) rules where the Rule.Provider property is set to MSExchange.Rules. However, you can remove all of the rules (Clear) for all of the providers from the collection.

Example

The following VBScript example displays the names of the rules in the TestUser account's Inbox on the Microsoft Exchange server SERVER, and whether they can be modified. Note that built-in rules do not have names.

Set mySession    = CreateObject("MAPI.Session")
mySession.Logon    "","",False,True,True,True,"SERVER" & vbLF & "TestUser"
Set myRules      = CreateObject("MSExchange.Rules")
myRules.Folder   = mySession.Inbox

For Each myRule In myRules
  If myRule.ReadOnly Then
    Wscript.Echo(myRule.Name & " cannot be modified")
  Else
    Wscript.Echo(myRule.Name & " can be modified")
  End If
Next

mySession.Logoff
Set mySession = Nothing
Set myRule    = Nothing
Set myRules   = Nothing