This topic has not yet been rated - Rate this topic

SetRuleOperation class

EWS Managed API

Represents an operation to update an Inbox rule.

Namespace:  Microsoft.Exchange.WebServices.Data
Assembly:  Microsoft.Exchange.WebServices (in Microsoft.Exchange.WebServices.dll)
public sealed class SetRuleOperation : RuleOperation

You can use this class to update the conditions and actions of an existing rule.

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. This class enables you to change the conditions or actions of a rule.

The following example searches the RuleCollection class to find an existing rule with the name "MoveInterestingToJunk" from the user's mailbox. If the rule exists, the Conditions properties are changed. The Conditions property removes the existing subject string filter and applies the new Conditions property that specifies that whenever an e-mail message arrives that has a string of "This is Junk" in the subject, the Exchange server is to take the existing actions. The rule is uploaded to the server when the service.UpdateInboxRules(new RuleOperation[] { setRuleOperation }, true) line is executed.

// Modify the "MoveInterestingToJunk" rule, if it exists.
// Get the RuleCollection.
RuleCollection ruleCollection = service.GetInboxRules("User1@Contoso.com");
foreach (Rule ruleinCollection in ruleCollection)
{
    if (ruleinCollection.DisplayName == "MoveInterestingToJunk")
    {
        ruleinCollection.Conditions.ContainsSubjectStrings.Clear();
        ruleinCollection.Conditions.ContainsSubjectStrings.Add("This is Junk");
        SetRuleOperation setRuleOperation = new SetRuleOperation(ruleinCollection);
        service.UpdateInboxRules(new RuleOperation[] { setRuleOperation }, 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:
© 2014 Microsoft. All rights reserved.