Active directory is used for managing users within a network, now a days Microsoft using cloud based solutions like Azure with SAML 2.0 etc.
However your question is about use of active directory then first of all you have to understand about active directory domain settings, AD is used for getting system user info to verify access level created for a specific user. In .Net simple code for getting AD user with domain is :
public static void Main() {
DisplayUser(WindowsIdentity.GetCurrent());
Console.ReadKey();
}
public static void DisplayUser(IIdentity id) {
WindowsIdentity winId = id as WindowsIdentity;
if (id == null) {
Console.WriteLine("Identity is not a windows identity");
return;
}
string userInQuestion = winId.Name.Split('\\')[1];
string myDomain = winId.Name.Split('\\')[0]; // this is the domain that the user is in
// the account that this program runs in should be authenticated in there
DirectoryEntry entry = new DirectoryEntry("LDAP://" + myDomain);
DirectorySearcher adSearcher = new DirectorySearcher(entry);
adSearcher.SearchScope = SearchScope.Subtree;
adSearcher.Filter = "(&(objectClass=user)(samaccountname=" + userInQuestion + "))";
SearchResult userObject = adSearcher.FindOne();
if (userObject != null) {
string[] props = new string[] { "title", "mail" };
foreach (string prop in props) {
Console.WriteLine("{0} : {1}", prop, userObject.Properties[prop][0]);
}
}
}
Actually both getting system user name & getting email address used for Microsoft login are different-2 processes.
To get system or OS user you can use below javascript code, known as a activeXObject, for this you have to enable activeXObject in IE from security tab (I just tested this for Internet explorer):
$(document).ready(function () {
try {
var activex = new ActiveXObject('WScript.Network');
alert(activex.userName);
} catch (ex) {
alert("unable to get user info");
}
}
So finally answer of your question you can't get email id directly without using AD or SAML etc.