域中搜索用户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;
        }

posted on 2011-03-31 15:08  catvi  阅读(566)  评论(0编辑  收藏  举报

导航