public static void Run()
{
try
{
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain");
Console.WriteLine("Downloading all messages from Inbox....");
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();
Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri);
string rootUri = client.GetMailboxInfo().RootUri;
// List all the folders from Exchange server
ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(rootUri);
foreach (ExchangeFolderInfo folderInfo in folderInfoCollection)
{
// Call the recursive method to read messages and get sub-folders
ListSubFolders(client, folderInfo);
}
Console.WriteLine("All messages downloaded.");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static void ListSubFolders(IEWSClient client, ExchangeFolderInfo folderInfo)