23

I would like to send email notifications as a task in my Azure DevOps build so that I can copy the build to other team projects and have it work automatically. I don't want to setup notifications for every new project I create. Thanks!

LeWoody
  • 3,593
  • 4
  • 25
  • 31

4 Answers4

10

You can install the Send Email task from the marketplace, and add it to your build pipline.

The extension takes care of sending email within your build or release pipeline.

enter image description here

But better way is configure a global notification settings for the builds.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
10

I tried to use "Send Email" to send something from my gmail but it didn't work out. I got the error message below

The SMTP server requires a secure connection or the client was not authenticated.

If you have a similar problem, I recommend you using SendGrid. It's more easier.

  1. Just create a resource "SendGrid" on Azure Portal.
  2. Create an API Key from SendGrid.
  3. Configure the pipeline with the key.

That's it. You don't have to config any SMTP setting and figure out what it is. enter image description here enter image description here enter image description here

Andy Lai
  • 1,714
  • 1
  • 14
  • 17
1

For an alternative solution, you can try CatLight notification tool.

It will show desktop alerts about build and release problems, as well as new PRs and work items.

Broken build alert

You can configure a shared dashboard for the team, and select all relevant projects and pipelines there. After that, the team members will be notified about failed builds and releases. Team members can also update those monitoring settings themselves at any time.

Azure DevOps can send too many notifications, and when developers check their inbox, many of those notifications are outdated. So, after a while they configure filters to hide them, defeating the purpose of notifications in the first place. CatLight has a dashboard that will show a summary of active alerts, and they will disappear from it as soon as alert is resolved. So it will be less noisy, and harder to ignore than emails.

List of active alerts

The tool is free for small teams and open-source, and their is paid version for companies.

alex
  • 12,464
  • 3
  • 46
  • 67
0

You can use the below PowerShell script to send email to a limited audience under the same project.

## fill out these only 5 places in the following script
$myorg = “your-org-onADo”
$myproj = “your-project-onADo”
$sendmailto = “user1@OrgEmailUnderThatProject.com,user1@OrgEmailUnderThatProject.com” ## email of receivers separated by coma
$mysubject = “This is your emails subject line” 
$mailbody = “This will be your emails body” 
#########################
##getting tfsids for the user under receivers list
$mailusers = “$sendmailto”
$mymailusers = $mailusers -split “,”
$pat = “Bearer $env:System_AccessToken”
$myurl =”https://dev.azure.com/${myorg}/_apis/projects/${myproj}/teams?api-version=5.1"
$data = Invoke-RestMethod -Uri “$myurl” -Headers @{Authorization = $pat}
$myteams = $data.value.id
##create list of members in all teams
$myusersarray = @()
foreach($myteam in $myteams) {
$usrurl = “https://dev.azure.com/${myorg}/_apis/projects/${myproj}/teams/"+$myteam+"/members?api-version=5.1"
$userdata = Invoke-RestMethod -Uri “$usrurl” -Headers @{Authorization = $pat}
$myusers = $userdata.value
foreach($myuser in $myusers) {
$myuserid = $myuser.identity.id
$myusermail = $myuser.identity.uniqueName
$myuserrecord = “$myuserid”+”:”+”$myusermail”
$myusersarray += $myuserrecord
}
}
## filter out all unique users
$myfinalusersaray = $myusersarray | sort -Unique
## create here the final hash of emails and tfsids
$myusershash = @{}
for ($i = 0; $i -lt $myfinalusersaray.count; $i++)
{
$myusershash[$myfinalusersaray[$i].split(“:”)[1]] = $myfinalusersaray[$i].split(“:”)[0]
}
##
## create the list of tfsid of mailers
foreach($mymail in $mymailusers) {
$myto = $myto +’”’+$myusershash[$mymail]+’”,’
}
##send mail using below API
$uri = “https://${myorg}.vsrm.visualstudio.com/${myproj}/_apis/Release/sendmail/$(RELEASE.RELEASEID)?api-version=3.2-preview.1"
$requestBody =
@”
{
“senderType”:1,
“to”:{“tfsIds”:[$myto]},
“body”:”${mailbody}”,
“subject”:”${mysubject}”
}
“@
Try {
Invoke-RestMethod -Uri $uri -Body $requestBody -Method POST -Headers @{Authorization = $pat} -ContentType “application/json”
}
Catch {
$_.Exception
}
MTK
  • 51
  • 5