Exemple #1
0
        public static void Run()
        {
            // ExStart:AccessCustomFolderUsingExchangeWebServiceClient
            // Create instance of EWSClient class by giving credentials
            IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");

            // Create ExchangeMailboxInfo, ExchangeMessageInfoCollection instance
            ExchangeMailboxInfo           mailbox       = client.GetMailboxInfo();
            ExchangeMessageInfoCollection messages      = null;
            ExchangeFolderInfo            subfolderInfo = new ExchangeFolderInfo();

            // Check if specified custom folder exisits and Get all the messages info from the target Uri
            client.FolderExists(mailbox.InboxUri, "TestInbox", out subfolderInfo);
            messages = client.FindMessages(subfolderInfo.Uri);

            // Parse all the messages info collection
            foreach (ExchangeMessageInfo info in messages)
            {
                string strMessageURI = info.UniqueUri;
                // now get the message details using FetchMessage()
                MailMessage msg = client.FetchMessage(strMessageURI);
                Console.WriteLine("Subject: " + msg.Subject);
            }
            // ExEnd:AccessCustomFolderUsingExchangeWebServiceClient
        }