访问其他用户';的邮箱以获取他的文件夹结构
本文关键字:获取 文件夹 结构 用户 访问 其他 | 更新日期: 2023-09-27 17:59:48
如何在不使用带有密码的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);
itemResult = getExchangeService().FindItems(usersFolderId, folderIdFilter, viewBase);
将只访问根文件夹中的项目,而对于大多数邮箱来说,根文件夹中没有任何内容。你所需要做的就是使用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);