Zumarta
Zumarta

Reputation: 145

Access other user's mailbox to get his folder structure

How is it possible to get a specific user's folder structure without using the ExchangeService with it password?

I surely have the rights to read the information but can't find a way to do that. I'm searching for something like that:

Mailbox userMailbox = new Mailbox(user);

WellKnownFolderName userFolderName = userMailbox.WellKnownFolderName.MsgFolderRoot;

FindFoldersResults findFoldersResults = exchangeService.FindFolders(userFolderName, new FolderView(int.MaxValue));

But actually I cannot access to other WellKnowFolderNames or directly to his folders.

Edit: I had a new approach but unfortunately it didn't return any items:

// Create mailbox for user
Mailbox mailbox = new Mailbox(user);

// Create a searchfolder to verify the used folder id is the same like the given folder id
SearchFilter.IsEqualTo folderIdFilter = new SearchFilter.IsEqualTo(ItemSchema.Id, folderId);

// Create new folder id
FolderId usersFolderId = new FolderId(WellKnownFolderName.Root, mailbox);

// Find items with search criteria
itemResult = getExchangeService().FindItems(usersFolderId, folderIdFilter, viewBase);

Upvotes: 1

Views: 895

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

itemResult = getExchangeService().FindItems(usersFolderId, folderIdFilter, viewBase);

Would only access the Items in the Root folder which for most mailboxes there won't be anything there. All you need to do is use the FolderId overload and the FindFolders eg

        FolderId RootFolder = new FolderId(WellKnownFolderName.MsgFolderRoot, "[email protected]");
        FolderView FolderVw = new FolderView(1000);
        FolderVw.Traversal = FolderTraversal.Deep;
        FindFoldersResults findFoldersResults = null;
        do
        {
            findFoldersResults = service.FindFolders(RootFolder, FolderVw);
            foreach (Folder mbFolder in findFoldersResults)
            {
                Console.WriteLine("Processing Folder " + mbFolder.DisplayName);
            }
            FolderVw.Offset += findFoldersResults.Folders.Count;
        } while (findFoldersResults.MoreAvailable);

Upvotes: 2

Related Questions