简体   繁体   中英

What is the method to get the public email of a User (C#, Graph API)?

How do I get the public email address of a User through Graph API? How does the code look like in C#?

Important Criteria for this functionality is: The User isn't logged in or Authorized by Azure AD, Graph API...

I want to search for a user by First and Last Name. Is this possible?

The code below returns the Email of a User filtered by DisplayName:

[HttpGet, Route("GetEmail")]
public async Task<ActionResult> GetEmail([FromForm] string filter)
{
    var users = await graphClient.Users
        .Request()
        .Filter("startswith(displayName,'" + filter.ToString() + "')")
        .Select(e => new {
            e.Mail,
            e.DisplayName,
            e.GivenName
        }).GetAsync();

    if (users.Count > 0)
        return Ok(users[0].Mail);
    else
        return BadRequest("No user found");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM