public static void Run() { // ExStart:CreateNewRuleOntheExchangeServers // Set Exchange Server 2010 web service URL, Username, password, domain information string mailboxURI = "https://ex2010/ews/exchange.asmx"; string username = "******"; string password = "******"; string domain = "ex2010.local"; // Connect to the Exchange Server NetworkCredential credential = new NetworkCredential(username, password, domain); IEWSClient client = EWSClient.GetEWSClient(mailboxURI, credential); Console.WriteLine("Connected to Exchange server"); InboxRule rule = new InboxRule(); rule.DisplayName = "Message from client ABC"; // Add conditions RulePredicates newRules = new RulePredicates(); // Set Subject contains string "ABC" and Add the conditions newRules.ContainsSubjectStrings.Add("ABC"); newRules.FromAddresses.Add(new MailAddress("*****@*****.**", true)); rule.Conditions = newRules; // Add Actions and Move the message to a folder RuleActions newActions = new RuleActions(); newActions.MoveToFolder = "120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA=="; rule.Actions = newActions; client.CreateInboxRule(rule); // ExEnd:CreateNewRuleOntheExchangeServer }
public static void Run() { // ExStart:CreateNewRuleOntheExchangeServer // Set Exchange Server web service URL, Username, password, domain information string mailboxURI = "https://ex2010/ews/exchange.asmx"; string username = "******"; string password = "******"; string domain = "ex2010.local"; // Connect to the Exchange Server NetworkCredential credential = new NetworkCredential(username, password, domain); IEWSClient client = EWSClient.GetEWSClient(mailboxURI, credential); Console.WriteLine("Connected to Exchange server"); InboxRule rule = new InboxRule(); rule.DisplayName = "Message from client ABC"; // Add conditions RulePredicates newRules = new RulePredicates(); // Set Subject contains string "ABC" and Add the conditions newRules.ContainsSubjectStrings.Add("ABC"); newRules.FromAddresses.Add(new MailAddress("*****@*****.**", true)); rule.Conditions = newRules; // Add Actions and Move the message to a folder RuleActions newActions = new RuleActions(); newActions.MoveToFolder = "120:AAMkADFjMjNjMmNjLWE3NzgtNGIzNC05OGIyLTAwNTgzNjRhN2EzNgAuAAAAAABbwP+Tkhs0TKx1GMf0D/cPAQD2lptUqri0QqRtJVHwOKJDAAACL5KNAAA=AQAAAA=="; rule.Actions = newActions; client.CreateInboxRule(rule); // ExEnd:CreateNewRuleOntheExchangeServer }