Hi @Tien Dang ,
I tested this use case scenario at my end and it is working fine as expected and the email is being successfully sent to the newly created users (without signing-in first) using Microsoft Graph API. I used the below APIs and sample JSON request body.
Note : We would need to wait for 2 to 3 minutes for SMTP email configuration / mapping to happen for the newly created & licensed user before sending the email As per my testing, new user mail box became available/active after 2 minutes and welcome email was succesfully sent.
1. Create User (Sample Request) :
POST https://graph.microsoft.com/v1.0/users
{
"accountEnabled": true,
"displayName": "TestUser111",
"mailNickname": "TestUser111",
"usageLocation": "IN",
"userPrincipalName": "******@o365XXXX.onmicrosoft.com",
"passwordProfile": {
"forceChangePasswordNextSignIn": false,
"password": "XXXXX"
}
}
Note : Make sure to set "usageLocation" propery while creating the user as shown in above sample JSON request body. A two letter country code (ISO standard 3166). This property is required for users that will be assigned licenses due to legal requirement to check for availability of services in countries. Examples include: US, IN, JP, and GB.
2. Assign license / subscription to the newly created user (Sample Request) :
POST /users/{id | userPrincipalName}/assignLicense
POST https://graph.microsoft.com/v1.0/users/******@o365XXXX.onmicrosoft.com/assignLicense
{
"addLicenses": [
{
"skuId": "c42b9cae-ea4f-4ab7-9717-81576235ccac"
}
],
"removeLicenses": []
}
Note : Product names and service plan identifiers for licensing. GUID of products can be refered in this documentation and GUID must be used to set "skuId" in the above JSON request body.
.
3. Wait for 2 minutes and then Send Email (Sample Request) :
POST https://graph.microsoft.com/v1.0/me/sendMail
{
"message": {
"subject": "Welcome Email Test",
"body": {
"contentType": "Text",
"content": "Welcome User"
},
"toRecipients": [
{
"emailAddress": {
"address": "******@o365XXXX.onmicrosoft.com"
}
}
]
}
}
Note : We would need to wait for 2 to 3 minutes for SMTP email configuration / mapping to happen for the newly created & licensed user before sending the email As per my testing, new user mail box became available/active after 2 minutes and welcome email was succesfully sent.
Final outout is that the new user has received welcome email as shown below :
Hope this helps.
If the answer is helpful, please click "Accept Answer" and kindly upvote it, so that it will be useful for other community users. If you have any further questions about this answer, please click "Comment".