Creating rules using Exchange

Hi,

Is it possible that we can create defined rules for mailbox using EWS? e.g. if I want to create a rule for inbox for a message, can I use your EWS for this purpose? I could not find any example in documentation for this.

Thanks

Hi Mark,

Thank you for writing to us.

Please give try to the following code sample for adding rule to your inbox and let us know your feedback.

ExchangeWebServiceClient client = GetAsposeEWSClient();
Console.WriteLine("Connected to Exchange 2010");

InboxRule rule = new InboxRule();
rule.DisplayName = "Message from client ABC";

// Add conditions
RulePredicates newRules = new RulePredicates();

// Subject contains string "ABC"
newRules.ContainsSubjectStrings.Add("ABC");

// From address is administrator@ex2010.local
newRules.FromAddresses.Add(new MailAddress("administrator@ex2010.local", true));

// Add the conditions
rule.Conditions = newRules;

// Add Actions
RuleActions newActions = new RuleActions();

// Move the message to a folder
newActions.MoveToFolder = "120:OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABAAMkADFjMjNjMmNjLWE3NzgtNGIzNC05bwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA==";

// Add the actions
rule.Actions = newActions;

// Create the rule now
client.CreateInboxRule(rule);