Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Rule class

Represents an individual Inbox rule in the mailbox.

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

public sealed class Rule : ComplexProperty

An Inbox rule is a set of Conditions, Exceptions, and associated Actions that enable clients to automatically organize, categorize, and act on messages as the messages are delivered to a folder. 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. Rule evaluation is triggered when e-mail messages are delivered in a user's mailbox or when messages are first saved to a folder. The Conditions in a Rule are evaluated against the properties of the incoming message. If the Conditions evaluate to true, the rule Actions are executed by the server.

The following example creates a new Rule and saves it to the messaging server. The rule contains an Actions and Conditions property. The Actions are:

  • The e-mail message is sent to the JunkEmail folder.

  • Assign a category of "Immediate".

  • Assign a category of "Internal use only".

The Conditions are:

  • The e-mail message contains the word "Interesting" in the subject.

// Create an inbox rule.
// If "Interesting" is in the e-mail's subject, move it into the Junk folder
// and assign two categories to the message.
Rule newRule = new Rule();
newRule.Actions.MoveToFolder = WellKnownFolderName.JunkEmail;
newRule.Conditions.ContainsSubjectStrings.Add("Interesting");
newRule.DisplayName = "MoveInterestingToJunk";
newRule.IsEnabled = true;

newRule.Priority = 1;
newRule.Actions.AssignCategories.Add("Immediate");
newRule.Actions.AssignCategories.Add("Internal use only.");

// 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.
Show:
© 2015 Microsoft