0

我需要特定组的所有电子邮件地址。请帮我

string filter1 = string.Format("(&(objectClass=group)(cn={0}))", "groupname");
        DirectorySearcher searcher = new DirectorySearcher(entry);
        searcher.Filter = filter1;
        searcher.SearchScope = SearchScope.Subtree;
        searcher.PropertiesToLoad.Add("member");
        SearchResult res = searcher.FindOne();
        ArrayList userNames = new ArrayList();
        if (res != null)
        {
            for (int counter = 0; counter <res.Properties["member"].Count; counter++)
            {
                string user = (string)res.Properties["member"][counter];
                userNames.Add(user);
            }
        }

我收到用户名和其他详细信息,但没有收到电子邮件。请告诉我直接找到每个用户的电子邮件地址的方法。

4

1 回答 1

0

您可以尝试使用此代码 - 基于PrincipalContext

var username = "username";
var domain = "domain";
var emailAddresses = new List<string>();

var principalContext = new PrincipalContext(ContextType.Domain, domain);
var userPrincipal  = UserPrincipal.FindByIdentity(principalContext, username);
// Add the "mail" entry
emailAddresses.Add(userPrincipal.EmailAddress);

链接: http: //msdn.microsoft.com/fr-fr/library/bb344891 (v=vs.90).aspx

于 2012-10-04T14:15:53.130 回答