public static void Run() { try { // ExStart:SaveMessagesToMemoryStream string datadir = RunExamples.GetDataDir_Exchange(); // Create instance of EWSClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); // Call ListMessages method to list messages info from Inbox ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); // Loop through the collection to get Message URI foreach (ExchangeMessageInfo msgInfo in msgCollection) { string strMessageURI = msgInfo.UniqueUri; // Now save the message in memory stream MemoryStream stream = new MemoryStream(); client.SaveMessage(strMessageURI, datadir + stream); } // ExEnd:SaveMessagesToMemoryStream } catch (Exception ex) { Console.Write(ex.Message); } }
public static void Run() { // ExStart:SaveMessagesUsingExchangeWebServices string dataDir = RunExamples.GetDataDir_Exchange(); // Create instance of IEWSClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); // Call ListMessages method to list messages info from Inbox ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); // Loop through the collection to get Message URI foreach (ExchangeMessageInfo msgInfo in msgCollection) { string strMessageURI = msgInfo.UniqueUri; // Now save the message in disk client.SaveMessage(strMessageURI, dataDir + msgInfo.MessageId + "out.eml"); } // ExEnd:SaveMessagesUsingExchangeWebServices }