Is it possible to get user email with loginname software in sharepoint?

I have a search function that returns an email address for a user when I have a user ID

private string getUserEmail(string userID)
{
    string userEmail = null;
    SPGroupCollection collGroups = SPContext.Current.Web.Groups;
    int userIDint = Convert.ToInt32(userID);
    foreach (SPGroup oGroup in collGroups)
    {
        userEmail = oGroup.Users.GetByID(userIDint).Email.ToString();
    }
    return userEmail;
}

with users I can use GetByID or GetByEmail, but what should I do if I have a domain name such as MyDomain \ myUsername and want to receive an email for this user?

Any help or links would be appreciated.

Thanks in advance.

+3
source share
1 answer

http://msdn.microsoft.com/en-us/library/ms414398.aspx

SPContext.Current.Web.AllUsers["loginname"].Email

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.ensureuser.aspx

SPContext.Current.Web.EnsureUser("loginname").Email
+10
source

Source: https://habr.com/ru/post/1786076/


All Articles