如何在不使用带有密码的ExchangeService的情况下获取特定用户的文件夹结构?
我当然有权阅读信息,但无法找到方法。我正在寻找类似的东西:
Mailbox userMailbox = new Mailbox(user);
WellKnownFolderName userFolderName = userMailbox.WellKnownFolderName.MsgFolderRoot;
FindFoldersResults findFoldersResults = exchangeService.FindFolders(userFolderName, new FolderView(int.MaxValue));
但实际上我无法访问其他WellKnowFolderNames或直接访问他的文件夹。
修改:我有一种新的方法,但不幸的是它没有退回任何项目:
// 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);
答案 0 :(得分:2)
itemResult = getExchangeService().FindItems(usersFolderId, folderIdFilter, viewBase);
只能访问Root文件夹中的Items,对于大多数邮箱,它们不会有任何内容。您需要做的就是使用FolderId重载和FindFolders,例如
FolderId RootFolder = new FolderId(WellKnownFolderName.MsgFolderRoot, "MailboxtoAccess@domain.com");
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);