Reputation: 547
I am listing users from SharePoint into custom database table for use in custom application. While adding these users to custom database we need the user Id from Azure Active Directory (not user ID from SharePoint).
So based on email of user from SharePoint I search the user in Azure AD and get the ID.
For some users I see that Mail field from Graph User object is null but has User Principal Name field filled with email. And for other users has both Mail and User Principal Name filled.
What is the reason Mail field for users is null? Which field should I rely on as email value?
Thank you!
Upvotes: 5
Views: 2657
Reputation: 11
userPrincipalName
may not equal email, for example, "xxx_xxx.com#EXT#@xxx.xxx.com"
Upvotes: 1
Reputation: 22515
What is the reason Mail field for users is null?
That value is for Guest User
only. When you would add a guest user
on your tenant there is a field with Email address
which has shown below would treated as mail
when you get user list using Microsoft Graph API
then you would see that email value.
PostMan Test:
Which field should I rely on as email value?
You can rely on userPrincipalName
which is User name
on azure portal that is mandatory property. Once you set it that would be treated as userPrincipalName
which you can be used for any scenario where you need tenant user email for example user login on portal
See the screenshot:
Hope that would help.
Upvotes: 7