域中搜索用户email

static public string GetEmailByUserID(string user_id, string pwd, string neededUser_ID)
{
string email = "";
DirectoryEntry entry
= new DirectoryEntry("LDAP://zone1.scb.net", user_id, pwd);
DirectorySearcher searcher
= new DirectorySearcher(entry);
searcher.Filter
= "(SAMAccountName=" + neededUser_ID + ")";
searcher.PropertiesToLoad.Add(
"SAMAccountName");
searcher.PropertiesToLoad.Add(
"mail");
SearchResult result
= searcher.FindOne();
if (result != null)
{
if (result.Properties.Contains("mail"))
{
email
= (string)result.Properties["mail"][0];
}
}
if (entry != null)
{
entry.Dispose();
}
return email;
}

转自:http://www.cnblogs.com/catvi/archive/2011/03/31/2001053.html

原文地址:https://www.cnblogs.com/poissonnotes/p/2063134.html