public static void Run() { // ExStart:CreateFoldersOnExchangeServerMailbox // Create instance of EWSClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); string inbox = client.MailboxInfo.InboxUri; string folderName1 = "EMAILNET-35054"; string subFolderName0 = "2015"; string folderName2 = folderName1 + "/" + subFolderName0; string folderName3 = folderName1 + " / 2015"; ExchangeFolderInfo rootFolderInfo = null; ExchangeFolderInfo folderInfo = null; try { client.UseSlashAsFolderSeparator = true; client.CreateFolder(client.MailboxInfo.InboxUri, folderName1); client.CreateFolder(client.MailboxInfo.InboxUri, folderName2); } finally { if (client.FolderExists(inbox, folderName1, out rootFolderInfo)) { if (client.FolderExists(inbox, folderName2, out folderInfo)) { client.DeleteFolder(folderInfo.Uri, true); } client.DeleteFolder(rootFolderInfo.Uri, true); } } // ExEnd:CreateFoldersOnExchangeServerMailbox }
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 }