Azure ad user mail attribute
In Azure Active Directory (Azure AD), the mail
attribute is a user attribute that stores the user's email address. This attribute is used to identify the user and is used in various scenarios, such as:
- Authentication: The
mail
attribute is used to verify the user's identity during the authentication process. - Directory searches: The
mail
attribute is used to search for users in the Azure AD directory. - Email notifications: The
mail
attribute is used to send email notifications to users, such as password reset notifications.
Here are some key points to note about the mail
attribute in Azure AD:
- Required: The
mail
attribute is not required for Azure AD users, but it is recommended to set it to ensure that users can be identified and authenticated correctly. - Format: The
mail
attribute should be in the format[email protected]
. - Case sensitivity: The
mail
attribute is case-insensitive, so[email protected]
and[email protected]
are considered the same. - Unique: The
mail
attribute should be unique for each user in the Azure AD directory. - Update: The
mail
attribute can be updated by the user or by an administrator.
You can manage the mail
attribute for Azure AD users using the Azure AD portal, PowerShell, or the Azure AD Graph API.
Azure AD portal:
- Sign in to the Azure AD portal as an administrator.
- Go to the "Users" tab.
- Select the user you want to manage.
- Click on the "Edit" button.
- Scroll down to the "Contact info" section.
- Update the "Email" field with the new email address.
PowerShell:
- Install the Azure AD PowerShell module.
- Connect to Azure AD using the
Connect-AzureAD
cmdlet. - Use the
Get-AzureADUser
cmdlet to retrieve the user object. - Use the
Set-AzureADUser
cmdlet to update themail
attribute.
Example:
$user = Get-AzureADUser -ObjectId <userObjectId>
$user.Mail = "[email protected]"
Set-AzureADUser -ObjectId <userObjectId> -User $user
Azure AD Graph API:
- Install the Azure AD Graph API client library.
- Use the
Get user
method to retrieve the user object. - Use the
Update user
method to update themail
attribute.
Example:
var client = new HttpClient();
var graphClient = new GraphServiceClient(client);
var user = await graphClient.Users["<userObjectId>"].Request().GetAsync();
user.Mail = "[email protected]";
await graphClient.Users["<userObjectId>"].Request().UpdateAsync(user);
Remember to replace <userObjectId>
with the actual object ID of the user you want to manage.