[英]Get ALL Mailboxes via EWS (Exchange WebServices) - not my own but also shared and group mailboxes
Can anyone provide me with a .NET (C# / VB) sample of how to get all mailboxes that I have access to?谁能向我提供一个 .NET (C# / VB) 示例,说明如何获取我有权访问的所有邮箱?
I have only been able to get my OWN mailbox via EWS - not ALL THE OTHER mailboxes that I also have access to through Outlook.我只能通过 EWS 获得我自己的邮箱 - 而不是我也可以通过 Outlook 访问的所有其他邮箱。
I don't have the names nor the id's of these mailboxes but isn't it possible to retrieve ALL mailboxes - including my own - that I am allowed to see - just as I can in Outlook?我没有这些邮箱的名称和 ID,但是否可以像 Outlook 中那样检索允许我查看的所有邮箱(包括我自己的邮箱)?
I am using Autodiscover to get my mailbox like this: service.AutodiscoverUrl("xxxx@ee.dd")
- this will perhaps only get my own mailbox and not all the rest?我正在使用自动发现来获取我的邮箱,如下所示:
service.AutodiscoverUrl("xxxx@ee.dd")
- 这可能只会获取我自己的邮箱,而不是所有 rest?
Please help??请帮忙??
You can do this by Using Autodiscover to get user settings , this is a completely separate service to the one with the AutodiscoverUrl method.您可以通过Using Autodiscover to get user settings来做到这一点,这是一个完全独立于使用 AutodiscoverUrl 方法的服务。
The setting name you need is AlternateMailboxes, this will give a collection of all the 'other' mailboxes you have access to.您需要的设置名称是 AlternateMailboxes,这将提供您有权访问的所有“其他”邮箱的集合。 You might then add the user's default mailbox to get a complete list.
然后您可以添加用户的默认邮箱以获得完整列表。
In c#:在 c#:
using Microsoft.Exchange.WebServices.Autodiscover; // from nuget package "Microsoft.Exchange.WebServices"
internal List<string> GetAccessibleMailboxes()
{
AutodiscoverService autodiscoverService = new AutodiscoverService("outlook.office365.com");
autodiscoverService.Credentials = networkCredential;
var userSmtpAddress = networkCredential.UserName;
GetUserSettingsResponse userresponse = autodiscoverService.GetUserSettings(
userSmtpAddress,
UserSettingName.AlternateMailboxes);
var alternateMailboxCollection = (AlternateMailboxCollection)userresponse.Settings[UserSettingName.AlternateMailboxes];
var smtpAddressList = alternateMailboxCollection.Entries.ToList().Select(a => a.SmtpAddress).ToList();
smtpAddressList.Add(userSmtpAddress);
return smtpAddressList;
}
The way I got around this was to define the group mailbox in question as a "mailbox" object and then obtain the FolderID for the particular folder. 我解决这个问题的方法是将有问题的组邮箱定义为“邮箱”对象,然后获取特定文件夹的FolderID。
Define mailbox object 定义邮箱对象
Mailbox gpmailbox = new Mailbox("mailbox@yourdomainname.com");
Get the FolderID (in this case, the Inbox) 获取FolderID(在本例中为收件箱)
FolderId gpInbox = new FolderId(WellKnownFolderName.Inbox, gpmailbox);
Use FolderID in your normal code (in this case I'm obtaining 100 messages) 在普通代码中使用FolderID(在这种情况下,我正在获取100条消息)
ItemView view = new ItemView(100); FindItemsResults<Item> results = hookToServer.FindItems(new FolderId(WellKnownFolderName.Inbox, gpmailbox), view);
The key is to grab the FolderID of the folder you need. 关键是获取所需文件夹的FolderID。 Hope this helps.
希望这可以帮助。
Edit: I also failed to note that my object "hookToServer" is simply the ExchangeService object. 编辑:我也没注意到我的对象“hookToServer”只是ExchangeService对象。 Here's how I defined it:
这是我如何定义它:
ExchangeService hookToServer = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
hookToServer.UseDefaultCredentials = true;
hookToServer.Url = new Uri("TheExchangeServer")
I also used this as reference: EWS 2007 Group Mailbox Guide 我还将此作为参考: EWS 2007组邮箱指南
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.