Email From ADO Pipeline

Copper Contributor



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 the ADO org (


2. This script below uses the Send Mail API, but gives this error, even though the 'message' field in the POST body is not empty.


What's the best way to send an email notification from an ADO pipeline, preferably without configuring an SMTP server?


@{$id=1; innerException=; message=Value cannot be null.
Parameter name: clientRecipients; typeName=System.ArgumentNullException, mscorlib; typeKey=ArgumentNullException; errorCode=0; eventId=0}
http status: 400


function SentEmail {
    $header = @{"Accept" = "application/json"; Authorization = ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $token)))) }
    $uri = "$org/$project/_apis/wit/sendmail?api-version=7.1-preview.1"

    $body = @{
        "message" = @{
            "subject" = 'TEST'
            "body"    = '<html><body>TEST</body></html>'
        "to"      = @{
            "emailAddresses" = 'email address removed for privacy reasons'
    } | ConvertTo-JSON -Depth 10
    Write-Host "uri: $uri"
    Write-Host "body: $body"
    Invoke-RestMethod -Method 'Post' -ContentType 'application/json' -Uri $uri -Headers $header -Body $body -StatusCodeVariable "httpStatus" -SkipHttpErrorCheck | Write-Host 
    Write-Host "http status: $httpStatus"

SentEmail -org "org" -project "project" -token "token"


1 Reply

@blashmet You will need to get valid ADO user ID first and then use it in email body:

#Get the tfsid
$userentitlementurl = "${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 = "${OrganizationName}/${ProjectName}/_apis/wit/sendmail?api-version=6.1-preview.1"

$requestBody =
  "message": {
      "to": {
          "tfIds": [
          "emailAddresses": [
            "email address removed for privacy reasons"
          "unresolvedEntityIds": []
      "subject": "cc",
      "body": "test",
      "cc": {
          "tfIds": [
      "replyTo": {
          "tfIds": [

Invoke-RestMethod -Uri $urimail -Body $requestBody -Method POST -ContentType "application/json" -Headers $AzureDevOpsAuthenicationHeader