c# - 枚举您可以使用 EWS 托管 API 访问的共享邮箱名称

标签 c# .net exchange-server exchangewebservices

我设置了共享邮箱并可以访问它及其子文件夹:

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

为此,我需要知道共享邮箱的名称 - 在此示例中,共享邮箱的名称是 shared.mailbox@domain.local。有没有办法枚举我可以访问的所有共享邮箱名称?我曾尝试在线搜索,但找不到解决方案。

最佳答案

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,

如果您谈论的是 Office365 组,您可以通过来自 git hub https://github.com/OfficeDev/ews-managed-api 的最新版托管 API 中的 GetUserUnifiedGroups 访问这些组例如

        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);
            }
        } 

授权访问启用自动映射的邮箱(这些是 Outlook 将自动映射到配置文件中的邮箱)例如 Add-MailboxPermission -AutoMapping 可以使用自动发现例如发现

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);
    }
}

然而,您刚刚将权限添加到邮箱或文件夹的邮箱无法知道其他邮箱,然后枚举每个邮箱 DACL 并进行检查。

关于c# - 枚举您可以使用 EWS 托管 API 访问的共享邮箱名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38881919/

相关文章:

c# - 获取数量缺货的日期

c# - Html 到 pdf 缺少一些字符 (itextsharp)

exchange-server - Item.Id.UniqueId 不唯一

c# - 我如何知道约会是否是私有(private)的

c# - Colspan 未按预期工作,仅跨越一列

c# - 表达式树 - 不必要的转换为 int32

c# - 改善绩效反射(reflect)——我应该考虑哪些替代方案?

c++ - 使用 dllexport 时出错?

c# - 如何使用 CsvHelper 编写从 DynamicObject 派生的类?

email - Powershell-编写来自Exchange的电子邮件的脚本