Return to Snippet

Revision: 46297
at May 17, 2011 03:49 by mecha


Initial Code
/// <summary>
/// Gets the user AD email address from Principal Context.
/// </summary>
/// <param name="username">The username.</param>
/// <returns>Returns the email address of AD user, and an empty string if not found.</returns>
public static string GetADUserEmailAddress(string username) {
	using (var pctx = new PrincipalContext(ContextType.Domain)) {
		using (UserPrincipal up = UserPrincipal.FindByIdentity(pctx, username)) {
			return up != null && !String.IsNullOrEmpty(up.EmailAddress) ? up.EmailAddress : string.Empty;
		}
	}
}

Initial URL


Initial Description


Initial Title
Get a Windows Active Directory User Email Address

Initial Tags


Initial Language
C#