简体   繁体   中英

Reading email from AD

I'm trying to get email adress from AD. I Use below code:

PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.SamAccountName = "XXX";
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
var found = srch.FindOne();

and this code returns this: 在此处输入图片说明

As You can see using Local window I access and read email but I need to do it for ~50 accounts. But I can not how to access that place by code. What should I Write after found

found.{something here}.EmailAdress

To get it work?

In order to get there I needed to convert found into DirectoryEntry using this code:

var a = found.GetUnderlyingObject() as DirectoryEntry;

And after that I was able to access mail from list of 71 parametres:

a.Properties["mail"].Value.ToString()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM