Get current user's email address in .NET
Reference System.DirectoryServices.AccountManagement
, then
using System.DirectoryServices.AccountManagement;
return UserPrincipal.Current.EmailAddress;
See .NET docs UserPrincipal.Current and UserPrincipal.EmailAddress.
Or with a timeout:
var task = Task.Run(() => UserPrincipal.Current.EmailAddress);
if (task.Wait(TimeSpan.FromSeconds(1)))
return task.Result;
If you're behind a Windows domain, you could always grab their email address out of Active Directory.
See Javier G. Lozano's example in his tutorial, "Querying Active Directory for User Emails".