【问题标题】:How to Look Up Email by Full Name in Active Directory?如何在 Active Directory 中按全名查找电子邮件?
【发布时间】:2026-02-16 20:05:01
【问题描述】:

我想使用 Active Directory 搜索用户的电子邮件。可用的是用户的全名(例如,电子邮件为“jdoe@example.com”的电子邮件为“John Doe”)。根据我的搜索,this 与我想要做的很接近——除了过滤器设置为“SAMAccountName”,这不是我所拥有的。

除非我误会,否则我只需要选择正确的属性并以相同的方式折腾全名即可。不幸的是,我不知道这个属性是什么,显然没有人不得不询问以这种方式搜索信息,这是一个相当大的列表(msdn * microsoft * com/en-us/library/ms675090(v =VS.85) * aspx,* 不允许我链接 2 个超链接,因为我没有 10 个代表) 的属性。

有谁知道如何使用用户的全名通过 Active Directory 查找来获取用户的电子邮件地址?

【问题讨论】:

    标签: search active-directory


    【解决方案1】:

    使用 3.5 System.DirectoryServices.AccountManagement.dll,可以使用 UserPrincipal FindByIdentity 方法:

    UserPrincipal.FindByIdentity(context, IdentityType.Name, "Lastname, Firstname");
    

    此调用通常包含在几个 using 语句中,如下所示:

    using (var ctx = new PrincipalContext(ContextType.Domain))
    {     
        using (var userPrincipal = UserPrincipal.FindByIdentity(ctx, IdentityType.Name, user))
        {
            return userPrincipal == null ? "" : userPrincipal.EmailAddress;
        }
     }
    

    【讨论】:

    • 谢谢您,先生,我到处寻找这个解决方案。像魅力一样工作!
    最近更新 更多