In AD here at work, there are several security groups that are included in the mail. I use the System.DirectoryServices.AccountManagement namespace as follows:
List<GroupPrincipal> result = new List<GroupPrincipal>(); using (PrincipalContext domain = new PrincipalContext(ContextType.Domain, userinfo[0])) using (UserPrincipal user = UserPrincipal.FindByIdentity(domain, username)) { if (user != null) { PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups(); int totalGroupCounter = 0; StringBuilder output = new StringBuilder(); List<GroupPrincipal> securityGroups = new List<GroupPrincipal>(); List<GroupPrincipal> distributionGroups = new List<GroupPrincipal>(); foreach (Principal group in groups) { totalGroupCounter++; if (((GroupPrincipal)group).IsSecurityGroup.Value) securityGroups.Add((GroupPrincipal)group); else distributionGroups.Add((GroupPrincipal)group); } } }
Armed with this information, what's the right way to find a group email address?
source share