Enumerating shared mailbox names you are able to access using EWS Managed API

强颜欢笑 提交于 2019-12-23 17:31:15

问题


I set up a shared mailbox and can access it and its sub-folders:

var folderId = new FolderId(WellKnownFolderName.MsgFolderRoot, "shared.mailbox@domain.local");
var folders = client.FindFolders(folderId, new FolderView(Int32.MaxValue));

To do this I need to know the name of the shared mailbox - in this example, the name of the shared mailbox is shared.mailbox@domain.local. Is there any way to enumerate through all of the shared mailbox names I am able to access? I have tried searching online but I could not find a solution.


回答1:


when you for example connect to an Office 365 account from Exchange and join a group, you see the shared mailbox of that group. When you then browse to your Office 365 mailbox online and not in Exchange, you see that group there as well,

If its a Office365 Group your talking about you can access these via the GetUserUnifiedGroups in the latest version of the Managed API from git hub https://github.com/OfficeDev/ews-managed-api eg

        RequestedUnifiedGroupsSet Group = new RequestedUnifiedGroupsSet();
        Group.FilterType = UnifiedGroupsFilterType.All;
        Group.SortDirection = SortDirection.Ascending;
        Group.SortType = UnifiedGroupsSortType.DisplayName;
        List<RequestedUnifiedGroupsSet> reqG = new List<RequestedUnifiedGroupsSet>();
        reqG.Add(Group);
        Collection<UnifiedGroupsSet> ugGroupSet = service.GetUserUnifiedGroups(reqG,"jcool@domain.com");
        foreach (UnifiedGroupsSet ugset in ugGroupSet)
        {
            foreach (UnifiedGroup ugGroup in ugset.Groups)
            {
                Console.WriteLine(ugGroup.SMTPAddress);
            }
        } 

Mailboxes that where granted access to where Auto-mapping is enabled (these are the Mailboxes that Outlook will Auto-map into a profile) eg Add-MailboxPermission -AutoMapping can be discovered using Autodiscover eg

AutodiscoverService adAutoDiscoverService = new AutodiscoverService(ExchangeVersion.Exchange2013_SP1);
adAutoDiscoverService.Credentials = new NetworkCredential("user@domain.com", "pass");
adAutoDiscoverService.EnableScpLookup = false;
adAutoDiscoverService.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
adAutoDiscoverService.PreAuthenticate = true;
adAutoDiscoverService.KeepAlive = false;




GetUserSettingsResponse gsp = adAutoDiscoverService.GetUserSettings("user@domain.com", UserSettingName.AlternateMailboxes);
Object Mailboxes = null;
if (gsp.Settings.TryGetValue(UserSettingName.AlternateMailboxes, out Mailboxes))
{
    foreach (AlternateMailbox Mailbox in ((AlternateMailboxCollection)Mailboxes).Entries) 
    {
        Console.WriteLine(Mailbox.SmtpAddress);
    }
}

However Mailboxes where you have just added the rights to a Mailbox or a Folder there is no way of knowing this other then enumerating each of the Mailboxes DACL and check that.




回答2:


Run this command in EMS to find all users mailbox name and export into csv:

Get-Mailbox -ResultSize Unlimited | Select Name,Alias,RecipientTypeDetails | Export-Csv c:\Users.csv

Then form your code, read form the file and loop through them I would recommend storing the folderid in a dictionary so that you can access them later on

And there is no way to find the mailboxes in a server directly form the api currently



来源:https://stackoverflow.com/questions/38881919/enumerating-shared-mailbox-names-you-are-able-to-access-using-ews-managed-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!