Home / Guides / Email a customer when a work item changes
Email a customer automatically when their Azure DevOps work item changes state
Your team moves a work item from New to Resolved and the customer who asked for it hears nothing. Azure DevOps can send an email for that change, but not to a customer who is outside your organization. This guide shows the ways to close that gap, gives you a receiver you can run and test, and says where each way stops.
Short answer.
Use a service hook. In Project settings > Service hooks, create a Web Hooks subscription for Work item updated, filtered to changes of the State field, and point it at a small service that reads the work item, finds the customer's address and sends the mail. Azure DevOps' own notification emails cannot do this, because a subscription sends to people or to one fixed address, not to a different customer per work item.
Why the built-in emails do not reach the customer
Azure DevOps notifications are built around the people on the event. A custom subscription can deliver to a
custom email address, but that is one address written into the subscription, not an address read from each work item.
Following a work item and @mentions notify the identities involved, which means people Azure DevOps knows. So a customer who
only filed a request through a form never gets the "your request is now Resolved" mail unless you send it yourself.
Option 1: a service hook and a receiver you own
You need three things: a place to keep the customer's address, the hook, and a receiver.
- The address. Add a custom field such as
Customer emailto the work item type (in an inherited process, under Organization settings > Process). Whatever creates the work item, a form, a flow or your own code, fills it in. - The hook. Under Project settings > Service hooks choose Create subscription, then Web Hooks. For the trigger pick Work item updated, set the Field filter to State, and narrow it with an area path, work item type or tag so that internal work does not fire it. On the action page enter the receiver's URL and an HTTP header that carries a secret, and press Test. Microsoft documents that you need to be a project administrator to do this, that the target should be HTTPS and cannot be localhost.
- The receiver. It checks the secret, reads the work item, decides whether the new state is one the customer should hear about, and sends the mail.
The script below is a demonstration receiver. It listens on one URL, answers the hook straight away, then asks Azure DevOps for the work item's current state, title and address instead of trusting the payload, maps the state to a customer-friendly label, and sends one mail. A state that is not in the map (your internal ones) sends nothing, and it remembers the last label it mailed per work item so a retried event does not send twice.
# Receive-StateChange.ps1: demo receiver for an Azure DevOps "Work item updated" web hook.
# Mails the customer when the work item's state moves to one you chose to show. Run it on a test machine first.
param(
[Parameter(Mandatory)][string]$Organization,
[Parameter(Mandatory)][string]$Project,
[Parameter(Mandatory)][string]$Secret, # the same value you put in the hook's HTTP headers
[Parameter(Mandatory)][string]$From,
[string]$SmtpServer = 'localhost',
[string]$PickupDirectory, # test: write .eml files here instead of sending
[string]$EmailField = 'Custom.CustomerEmail', # a custom field that holds the customer's address
[string]$Prefix = 'http://localhost:8080/',
[string]$AdoBase = 'https://dev.azure.com'
)
# What the customer is told. A state that is not listed here (your internal ones) sends nothing.
$PublicState = @{ 'New' = 'Received'; 'Active' = 'In progress'; 'Resolved' = 'Fixed'; 'Closed' = 'Closed' }
$lastMailed = @{} # work item id -> last state label mailed (stops duplicates when Azure DevOps retries)
# 499b84ac-1321-427f-aa17-267ca6975798 is the resource ID of Azure DevOps.
$token = az account get-access-token --resource 499b84ac-1321-427f-aa17-267ca6975798 --query accessToken -o tsv
if (-not $token) { throw 'No Azure DevOps token. Sign in with az login first.' }
$listener = [System.Net.HttpListener]::new()
$listener.Prefixes.Add($Prefix)
$listener.Start()
Write-Host "Listening on $Prefix"
while ($listener.IsListening) {
$ctx = $listener.GetContext()
$ok = $ctx.Request.Headers['X-Hook-Secret'] -ceq $Secret
# Read the body BEFORE answering: closing the response closes the request stream too.
$body = [System.IO.StreamReader]::new($ctx.Request.InputStream, $ctx.Request.ContentEncoding).ReadToEnd()
$ctx.Response.StatusCode = if ($ok) { 200 } else { 401 }
$ctx.Response.Close() # answer first: the hook should not wait for the mail
if (-not $ok) { Write-Warning 'Rejected a request with the wrong secret.'; continue }
try {
$evt = $body | ConvertFrom-Json
# The work item id: check this against the payload your hook really sends (use the hook's Test button).
$id = if ($evt.resource.workItemId) { $evt.resource.workItemId } elseif ($evt.resource.revision.id) { $evt.resource.revision.id } else { $evt.resource.id }
# Read the current state and address from Azure DevOps instead of trusting the payload.
$url = '{0}/{1}/{2}/_apis/wit/workitems/{3}?fields=System.Title,System.State,{4}&api-version=7.1' -f
$AdoBase, $Organization, [uri]::EscapeDataString($Project), $id, $EmailField
$wi = Invoke-RestMethod -Uri $url -Headers @{ Authorization = "Bearer $token" }
$state = $wi.fields.'System.State'
$label = $PublicState[$state]
if (-not $label) { Write-Host "#$id state '$state' is internal: no mail."; continue }
if ($lastMailed[$id] -eq $label) { Write-Host "#$id already told '$label': no mail."; continue }
$to = [string]$wi.fields.$EmailField
try { $null = [System.Net.Mail.MailAddress]::new($to) } catch { Write-Warning "#$id has no usable address in $EmailField."; continue }
$msg = [System.Net.Mail.MailMessage]::new($From, $to, "Your request #$id is now: $label",
"Your request `"$($wi.fields.'System.Title')`" (#$id) is now: $label.")
$smtp = [System.Net.Mail.SmtpClient]::new($SmtpServer)
if ($PickupDirectory) { $smtp.DeliveryMethod = 'SpecifiedPickupDirectory'; $smtp.PickupDirectoryLocation = $PickupDirectory }
$smtp.Send($msg)
$lastMailed[$id] = $label
Write-Host "#$id mailed '$label' to $to."
}
catch { Write-Warning "Could not process the event: $($_.Exception.Message)" }
}
Try it on a test machine first, writing the mail to a folder instead of a mail server:
.\Receive-StateChange.ps1 -Organization contoso -Project Support -Secret 'a-long-random-value' `
-From 'desk@example.com' -PickupDirectory C:\Temp\mail -Prefix 'http://localhost:8080/'
Things to know before you rely on it:
-
It reads the work item with
GET .../_apis/wit/workitems/{id}?fields=...&api-version=7.1. Use the hook's Test button, or a request catcher, to see what your subscription really sends, and check the line that finds the work item id against it. The script triesresource.workItemId, then the revision, thenresource.id. - It listens on plain HTTP, so it is a test harness. For production host the same logic as an Azure Function or a web app behind HTTPS, and sign in to Azure DevOps with a managed identity or a token kept in a secret store rather than the Azure CLI.
- The remembered labels live in memory. A real service keeps them in a table, so a restart does not mail everyone again.
- Mail from your own domain needs SPF and DKIM set up, or the first status email may land in spam. The sending side (SMTP relay, bounces, an unsubscribe line) is yours to run.
Option 2: Power Automate
The Azure DevOps connector has a When a work item is updated trigger, and Microsoft lists the connector as Premium for Power Automate. Its filters are assigned to, work item type, area path, iteration path, priority and created by. There is no "state changed" filter, so the flow has to remember the last state itself, for example in a field of the work item or a table. The connector page also lists a known limitation: the trigger is skipped when links are added or removed. It suits you if you already pay for Premium and do not want to host anything, and it still needs the customer's address on the work item.
Option 3: only tell your own team
If the audience is your team, skip all of this. A team subscription under Project settings > Notifications mails the members when a work item changes, and a service hook for Teams or Slack posts to a channel. It does not mail a customer.
Where the do-it-yourself route stops
- Public wording. Your process states ("Triage", "Blocked by legal") are not what a customer should read. You keep the label map up to date.
- Replies. The customer will answer the mail. Without a reply address that turns into a comment, the answer lands in your inbox, not on the work item.
- Comments. Telling the customer about a new reply is a second hook with the same rules again, plus a way to keep internal comments out.
- Operations. Retries, bounces, a customer who changes address, and who looks after the receiver at 3 a.m.
Questions
Can Azure DevOps email a customer when a work item changes?
Not by itself. Notification subscriptions deliver to people or to one fixed custom email address, not to an address read from each work item. To mail a different customer per work item you use a service hook (Web Hooks, Work item updated, filtered to the State field) or a Power Automate flow, and send the email from your own code or flow.
How do I trigger an email only when the state changes?
Create the service hook for Work item updated and set the Field filter to State. The event then fires only when that field changes. For several fields at once you create one subscription per field or use the REST API.
Do I need Power Automate Premium for this?
If you use the Azure DevOps connector, Microsoft lists it as Premium for Power Automate. A service hook with your own receiver needs no Power Automate license, but you host and run the receiver.
Can the hook send to localhost or an HTTP address?
Not to localhost: Microsoft documents that web hooks cannot target localhost or special address ranges, and it recommends HTTPS only. Host the receiver on a public HTTPS endpoint, or test with a request catcher first.
How does BoardwalkDesk email customers about their tickets?
When the status of a ticket changes in Azure DevOps, the customer gets an email with the new status and a link to the ticket, and a new team reply is mailed the same way. Comments that start with [internal] or are hidden are never mailed, and the same change is not mailed twice.
Related
- Let customers create Azure DevOps work items without a license
- A customer support portal for Azure Boards: your options compared
- BoardwalkDesk: a customer service desk for Azure DevOps
- All guides
Sources (Microsoft Learn): Service hook events, Webhooks, Determine recipients of notification emails, Azure DevOps connector, Work Items - Get Work Item.