Forum Discussion
blashmet
Jul 26, 2022Copper Contributor
Email From ADO Pipeline
Hi, I've tried a few different methods of sending mail from an azure_pipelines.yml file. 1. The manual validation task here did not send an email even if that users email is registered with t...
alexanderogorodnikov
Jul 19, 2023Copper Contributor
blashmet You will need to get valid ADO user ID first and then use it in email body:
#Get the tfsid
$userentitlementurl = "https://vsaex.dev.azure.com/${OrganizationName}/_apis/userentitlements?api-version=7.1-preview.1"
$response = Invoke-RestMethod -Uri $userentitlementurl -Method Get -Headers $AzureDevOpsAuthenicationHeader
$sendmailto = "email address removed for privacy reasons"
#Filter by sendmailto
$tfsid = ($response.value| where {$_.user.mailAddress -eq $sendmailto}).id
Write-Host $tfsid
#send mail
$urimail = "https://dev.azure.com/${OrganizationName}/${ProjectName}/_apis/wit/sendmail?api-version=6.1-preview.1"
$requestBody =
@"
{
"message": {
"to": {
"tfIds": [
$tfsid
],
"emailAddresses": [
"email address removed for privacy reasons"
],
"unresolvedEntityIds": []
},
"subject": "cc",
"body": "test",
"cc": {
"tfIds": [
$tfsid
]
},
"replyTo": {
"tfIds": [
$tfsid
]
}
}
}
"@
Invoke-RestMethod -Uri $urimail -Body $requestBody -Method POST -ContentType "application/json" -Headers $AzureDevOpsAuthenicationHeader