I would like to know the email address of the user (assuming she's in a typical Windows office network). This is in a C# application. Perhaps something to the effect of
CurrentUser.EmailAddress;
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With