示例#1
0
        public static void Run()
        {
            // ExStart:UpdateRuleOntheExchangeServer
            // Set mailboxURI, 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");

            // Get all Inbox Rules
            InboxRule[] inboxRules = client.GetInboxRules();

            // Loop through each rule
            foreach (InboxRule inboxRule in inboxRules)
            {
                Console.WriteLine("Display Name: " + inboxRule.DisplayName);
                if (inboxRule.DisplayName == "Message from client ABC")
                {
                    Console.WriteLine("Updating the rule....");
                    inboxRule.Conditions.FromAddresses[0] = new MailAddress("*****@*****.**", true);
                    client.UpdateInboxRule(inboxRule);
                }
            }
            // ExEnd:UpdateRuleOntheExchangeServer
        }
示例#2
0
        public static void Run()
        {
            // ExStart:ExchangeServerReadRules
            // Set mailboxURI, 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");

            // Get all Inbox Rules
            InboxRule[] inboxRules = client.GetInboxRules();

            // Display information about each rule
            foreach (InboxRule inboxRule in inboxRules)
            {
                Console.WriteLine("Display Name: " + inboxRule.DisplayName);

                // Check if there is a "From Address" condition
                if (inboxRule.Conditions.FromAddresses.Count > 0)
                {
                    foreach (MailAddress fromAddress in inboxRule.Conditions.FromAddresses)
                    {
                        Console.WriteLine("From: " + fromAddress.DisplayName + " - " + fromAddress.Address);
                    }
                }
                // Check if there is a "Subject Contains" condition
                if (inboxRule.Conditions.ContainsSubjectStrings.Count > 0)
                {
                    foreach (String subject in inboxRule.Conditions.ContainsSubjectStrings)
                    {
                        Console.WriteLine("Subject contains: " + subject);
                    }
                }
                // Check if there is a "Move to Folder" action
                if (inboxRule.Actions.MoveToFolder.Length > 0)
                {
                    Console.WriteLine("Move message to folder: " + inboxRule.Actions.MoveToFolder);
                }
            }
            // ExEnd:ExchangeServerReadRules
        }