I want to search for a user’s email by using Active Directory. Available is the user’s full name (ex. “John Doe” for the email with an email “jdoe@example.com”). From what I’ve searched, this comes close to what I’m looking to do — except that the Filter is set to “SAMAccountName”, which is not what I have.
Unless I’m misunderstanding, I just need to pick the right attribute and toss in the full name name in the same way. Unfortunately, I don’t know what this attribute is, apparently no one has had to ask about searching for information in this manner, and that is a pretty big list (msdn * microsoft * com/en-us/library/ms675090(v=VS.85) * aspx, stackoverflow didn’t let me link 2 hyperlinks because I don’t have 10 rep) of attributes.
Does anyone know how to obtain the user’s email address through an Active Directory lookup by using the user’s full name?
Using the 3.5 System.DirectoryServices.AccountManagement.dll, you can use the UserPrincipal FindByIdentity method:
This call is generally wrapped inside a couple of using statements like the following: