通过电子邮件地址在ActiveDirectory中查找用户
如何通过电子邮件地址查询ActiveDirectory用户? 给定用户可以有多个电子邮件,例如john.smite@acme.com和jsmith@acme.com。 对于给定的电子邮件,我该如何取回A / D用户?
我正在用C#编程。
您可以使用以下代码搜索AD:
DirectoryEntry adEntry = null; private void SetADInfoAndCredentials() { adEntry = new DirectoryEntry("LDAP://" + ad_textBox.Text); adEntry.Username = user_textBox.Text; adEntry.Password = pw_textBox.Text; } private void SearchForMailInAD() { DirectorySearcher adSearcher = new DirectorySearcher(adEntry); adSearcher.Filter = ("mail=" + mail_textBox.Text); SearchResultCollection coll = adSearcher.FindAll(); foreach (SearchResult item in coll) { foundUsers_listBox.Items.Add(item.GetDirectoryEntry()); } }
€:这将搜索托管所有邮件地址的proxyAddresses中的邮件地址
上述就是C#学习教程:通过电子邮件地址在ActiveDirectory中查找用户分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
public static SearchResultCollection FindAccountByEmail(string pEmailAddress) { string filter = string.Format("(proxyaddresses=SMTP:{0})", email); using (DirectoryEntry gc = new DirectoryEntry("LDAP:")) { foreach (DirectoryEntry z in gc.Children) { using (DirectoryEntry root = z) { using (DirectorySearcher searcher = new DirectorySearcher(root, filter, new string[] { "proxyAddresses", "objectGuid", "displayName", "distinguishedName" })) { searcher.ReferralChasing = ReferralChasingOption.All; SearchResultCollection result = searcher.FindAll(); return result; } } } } return null; }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/990150.html