我想从Active Directory中获取所有电子邮件地址。在下面,我尝试了这种情况,但没有收到所有电子邮件。我需要所有电子邮件,例如ObjectClass=group
,ObjectClass=user
等
我尝试过这些,
deSearch.Filter = "(|(ObjectClass=user)(ObjectClass=group))";
deSearch.Filter = "(mail=*@abc.com)";
完整代码:
DirectoryEntry de = new DirectoryEntry();
de.AuthenticationType = AuthenticationTypes.Secure;
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
deSearch.Filter = "(mail=*)";
SearchResultCollection results = deSearch.FindAll();
foreach (SearchResult sResultSet in results)
{
if (sResultSet.Properties["Mail"].Count > 0)
{
if (sResultSet.Properties.Contains("Mail")
{
mailPackage.Mail = sResultSet.Properties["Mail"][0].ToString();
}
mailList.Add(mailPackage);
}
}
return mailList;