简体   繁体   English

通过 EWS (Exchange WebServices) 获取所有邮箱 - 不是我自己的邮箱,还有共享邮箱和群组邮箱

[英]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。

  1. Define mailbox object 定义邮箱对象

     Mailbox gpmailbox = new Mailbox("mailbox@yourdomainname.com"); 
  2. Get the FolderID (in this case, the Inbox) 获取FolderID(在本例中为收件箱)

     FolderId gpInbox = new FolderId(WellKnownFolderName.Inbox, gpmailbox); 
  3. 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.

相关问题 共享收件箱你如何让 vba 去那里而不是我自己的收件箱 - shared inbox how do you get vba to go there instead of my own inbox Microsoft.Exchange.WebServices.Data.ServiceResponseException:“没有可用的公用文件夹服务器。” - Microsoft.Exchange.WebServices.Data.ServiceResponseException: 'There are no public folder servers available.' PowerShell 2 - 能够获取所有共享文件夹和共享对象 - PowerShell 2 - Being Able To Get All Share Folders And People Shared With 在我的应用程序的资产目录中列出所有文件和文件夹(以及子文件夹),并检查资产是文件还是文件夹 - List all files and folders (also Subfolders) in Assets Directory in my App and check if an asset is a file or a folder 通过PHP脚本从目录中获取所有文件名 - Get all filenames from directory via PHP script 我自己的目录中的Android数据库 - Android Database in my own directory 如何对指定控制器的部分共享视图进行分组? - How to group partial shared views for specified controllers? 将文件夹路径的所有目录递归到我的Poco中 - Get All Directories of a Folder Path Recursively into my Poco 如何通过 Powershell 从 sharepoint 中的文件夹中获取具有属性(由我自己自定义创建的列)的所有文件? - How to get all the files from a folder in sharepoint with there properties(Columns which were custom created by myself) via Powershell? 所有站点(/ usr / share /)Apache的共享文件夹 - Shared folder for all sites (/usr/share/) Apache
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM