Created
July 10, 2023 17:05
-
-
Save pamanes/4bd1664f1f394efbc111bcf44a838681 to your computer and use it in GitHub Desktop.
Azure PowerShell Task for Build Pipeline E-Mail Send
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Required variables | |
$env:SYSTEM_ACCESSTOKEN | |
$env:SYSTEM_TEAMFOUNDATIONSERVERURI | |
$env:SYSTEM_TEAMPROJECTID | |
$env:SYSTEM_TEAMPROJECT | |
$workItemId = YOUR_WORK_ITEM_ID_HERE | |
$output = "BODY OF EMAIL HERE" | |
# Derived variables | |
$adoHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$env:SYSTEM_ACCESSTOKEN")) } | |
$organization = ($env:SYSTEM_TEAMFOUNDATIONSERVERURI -split "/")[3] | |
$emailAddresses = @() | |
$tfIds = @() | |
$emailAddresses+="[email protected]" | |
$tfIds+="YOUR_TFID_HERE" | |
# Prepare email body | |
$requestBody = @{ | |
message = @{ | |
to = @{ | |
emailAddresses = $emailAddresses | |
tfIds = $tfIds | |
} | |
cc = @{} | |
replyTo = @{} | |
body = $output | |
subject = "SUBJECT HERE" | |
} | |
projectId = $env:SYSTEM_TEAMPROJECTID | |
ids = @($workItemId) | |
} | |
$arguments = @{ | |
Uri = ("{0}{1}/_apis/wit/sendmail?api-version=7.0" -f $env:SYSTEM_TEAMFOUNDATIONSERVERURI, $env:SYSTEM_TEAMPROJECT) | |
Method = 'POST' | |
Headers = $adoHeader | |
Body = ConvertTo-Json -InputObject $requestBody -Depth 5 | |
ContentType = 'application/json; charset=utf-8' | |
} | |
Invoke-RestMethod @arguments |
hi @ggirodda , I haven't been able to send HTML, even though the docs state that the body is in HTML format!
https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/send-mail/send-mail?view=azure-devops-rest-7.0
thanks, and I'm glad this worked out for you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @pamanes , this is the only helpful answer I found in the net. Did you try to send body content in html format? In my case the html is displayied as text when I receive the email.
Thank you for any information