We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Subfolders with EWS

I have some code using the EWSClient where I use a folder string to get messages. This works perfectly for top-level folders such as Inbox or Sent Items, but when I try to access a subfolder I cannot. I’ve tried variations that work with IMAP such as “Inbox/Subfolder” to no avail. Is there a folder name structure with EWS I can use, or do I need to provide a list of folders that use the folder URI under the hood?

The overload of ListMessages I’m using is ‘ExchangeMessageInfoCollection ListMessages(string folder, MailQuery query, bool recursive);’

Here is an extract of my code:

 using (var client = EWSClient.GetEWSClient(EmailSettings.Host, EmailSettings.Login, EmailSettings.Password))
     client.Timeout = EmailSettings.Timeout;

     var builder = new ExchangeQueryBuilder();


     var messageInfos = client.ListMessages(EmailSettings.Inbox, builder.GetQuery(), false);

     SendLog(TraceEventType.Verbose, string.Format("Found {0} unread messages", messageInfos.Count));


I have tried understanding your requirements and like to share that following option is possible using Aspose.Email IEWSClient that you can consider. If it’s otherwise, can you please elaborate further so that I may try helping you further.

    public static void TestClient()

        IEWSClient client = GetExchangeEWSClient();
        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);

    private static void ListSubFolders(IEWSClient client, ExchangeFolderInfo folderInfo)
            // If this folder has sub-folders, call this method recursively to get messages
            ExchangeFolderInfoCollection folderInfoCollection = client.ListSubFolders(folderInfo.Uri);
            foreach (ExchangeFolderInfo subfolderInfo in folderInfoCollection)
                ListSubFolders(client, subfolderInfo);
        catch (Exception)