4

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.

Alexandru
  • 12,264
  • 17
  • 113
  • 208

2 Answers2

3

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.

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
1

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

rojobo
  • 476
  • 4
  • 16
  • Won't that command list all mailboxes for all users including shared mailboxes? This would be a huge pain because I only care to see what shared mailboxes the current user has access to, and this would be pure trial-and-error. – Alexandru Aug 10 '16 at 20:07
  • Im no system admin but im pretty sure you can obtain just the shared ones using more options you could try asking that question in the appropriate stack exchange – rojobo Aug 10 '16 at 20:10
  • found this https://social.technet.microsoft.com/Forums/exchange/en-US/8209a0a6-a430-48a7-8121-216d23bdd811/using-powershell-to-find-shared-mailboxes-with-what-role-assignment-policy-is-being-applied?forum=exchange2010 – rojobo Aug 10 '16 at 20:12
  • Thanks, this is helpful stuff for sure, I just don't quite understand why the API doesn't expose it. I mean, 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, so they must have a way of tracking that, whether its active directory or something else. I can't help but wonder if the managed API actually does expose some sort of a buried solution for all of this or not... – Alexandru Aug 10 '16 at 20:22
  • 1
    I hear you...even Hening Krause (known for being part of the EWS team) could not provide an answer to a similar question...http://stackoverflow.com/questions/4217527/ews-access-shared-calendars – rojobo Aug 10 '16 at 20:28