Hello,
We are working on a custom application where we need to store user's email in our database. We use Azure AD for authentication.
We came across different client's Azure AD and found that for some users mail field is null. So we need to find a way to get user's correct email.
In one client's case, AD has alternate email field with correct email for user. However for other client, they have user's email same as user principal name.
So it seems there is no standard way to depend on these fields to get correct email address. Is this right or there is a field that we can depend on to get the correct email?
Currently we use below logic:
1. Check if mail field has value, if yes use mail field as email
2. If mail is null, then check user principal name. If UPN has #ext# (for external users), then use alternate email field as email.
3. If UPN do not have #ext# then use UPN as email.
Will this work? Or external user's UPN can be edited to remove #ext# which would cause problem with our logic?
Thank you!