Email From ADO Pipeline

New 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"


0 Replies