域中搜索用户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;
        }
原文地址:https://www.cnblogs.com/catvi/p/2001053.html