0

I am looking for a way how to find some users emaill address based on their domain id. I found many solutions for Current users via

user = clientContext.get_web().get_currentUser();

however i want to find info about different user. I was trying to google for some time but did not find solution. Is there some way to retrieve users email for example with similar method?

Something like this

user = clientContext.get_web().getinfo(SPECIFIC USER DOMAIN NAME)

Thanks so much.

Rudolf
  • 17
  • 3

2 Answers2

0

Try to use this REST API endpoint to have all users information:

http://<siteUrl>/_api/Web/SiteUserInfoList/items

then filter by the field you know and select the information you need ($select=EMail)

RiccardoGDev
  • 408
  • 2
  • 10
0

The following example code for your reference, modify the "loginName" in the code and add the code into a script editor web part in page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
    var loginName="domain\\username";
    getUserEmailByLoginName(loginName);
});
function getUserEmailByLoginName(loginName) {
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers?$select=Email&$filter=substringof('"+loginName+"',LoginName)";                  
    //execute AJAX request
    $.ajax({
        url: requestUri,
        type: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        success: function (data) {
            if(data.d.results.length>0){
                alert(data.d.results[0].Email); 
            }

        },
        error: function () {
            //alert("Failed to get details");                
        }
    });
}
</script>
LZ_MSFT
  • 6,219
  • 1
  • 7
  • 7
  • Thank you very much exactly what i was looking for. For anyone interested here is the link also with other attributes that can be retrieved.

    https://sharepoint.stackexchange.com/a/171290/82539

    – Rudolf Apr 08 '19 at 06:42
  • I came to a problem that this connects to siteusers list. Is there a way how to connect to whole active directory domain where the users are? because like this i cannot find many users, only ones that have access to sharepoint or are part of siteusers list from past. Thanks. – Rudolf Apr 15 '19 at 14:36
  • If you want to get all users, you need remove the filter in the rest api, like /_api/web/siteusers – LZ_MSFT Apr 16 '19 at 01:22