CreateRuleOperation class

Represents an operation to create an Inbox rule.

Namespace:  Microsoft.Exchange.WebServices.Data
Assembly:  Microsoft.Exchange.WebServices (in Microsoft.Exchange.WebServices.dll)

public sealed class CreateRuleOperation : RuleOperation

Inbox rules are sets of Conditions and associated Actions that enable clients to automatically organize, categorize, and act on messages as the messages are delivered to a folder.

This class derives from the RuleOperation class.

When a rule is created, it is stored on the Exchange server. When a message arrives, the Exchange server evaluates the message and determines whether it has fulfilled any rule Conditions. If it has, the Exchange server will then process the message according to the rule Actions. For example, a rule can be created to require that any incoming mail that contains a certain string in the subject be automatically moved to a predetermined folder.

The following example creates a rule with the name "MoveInterestingToJunk". The rule has a Conditions property that specifies that whenever an e-mail message arrives that has the string "Interesting" in the subject line, the message is to be moved to the Junk E-mail folder. The rule is uploaded to the server in the service.UpdateInboxRules(new RuleOperation[] { createOperation }, true) line.

// Create an Inbox rule.
// If "Interesting" is in the message's subject line, move it into the Junk E-mail folder.
Rule newRule = new Rule();
newRule.DisplayName = "MoveInterestingToJunk";
newRule.Priority = 1;
newRule.IsEnabled = true;
newRule.Actions.MoveToFolder = WellKnownFolderName.JunkEmail;

// Create the CreateRuleOperation.
CreateRuleOperation createRuleOperation = new CreateRuleOperation(newRule);
service.UpdateInboxRules(new RuleOperation[] { createRuleOperation }, true);

Any public static ( in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.