Smart Statistics · Power Automate tutorial
Power Automate HTML Emails: Keep Customer Text Out of the Markup
A customer writes an ampersand, a comparison sign or a phrase in angle brackets. Your flow runs successfully, but the email no longer shows exactly what they entered. Keep the template in control by encoding plain text before inserting it into HTML.
29 November 2026 · A practical lab for UK business automation teams
Illustrative example · all dashboard figures
Service notification: encoding test bench
Design status: plain text remains text.
Workflow: raw note → normalise missing value → encode characters → add trusted template → test email.
The featured image is a conceptual illustration. Encoding preserves wording; it does not rewrite customer messages.
Why a green flow run is not enough
A repairs business uses an internal email to hand customer notes to its service team. A note such as <b>urgent</b> must appear literally when it is plain-text input. Inserted directly into a hand-built HTML body, it can instead become bold text. Other markup can change layout or introduce misleading links.
The problem is at the output boundary. Keep the original source value unchanged and encode it when building the HTML. OWASP distinguishes HTML text encoding from attribute, URL and other contexts; this tutorial uses customer text only between fixed paragraph tags. [3]
You need permission to create a cloud flow and an authorised Office 365 Outlook connection for the sending step. Confirm your organisation’s licensing and connector policies. Use invented data and your own approved test mailbox.
Build a small, repeatable input
Create an Instant cloud flow with Manually trigger a flow. Add Data Operations → Compose and rename it Raw_note before creating downstream expressions. Paste this as ordinary text, not an expression:
A&B Repairs: <b>urgent</b> — use "side door"; customer's note.
Add another Compose named Normalised_note. In its Expression editor, enter the following without a leading @:
string(coalesce(outputs('Raw_note'), ''))
This lab treats null as an empty string. It does not treat an empty note as a complete business request. If the note is mandatory, validate it separately before sending. Microsoft documents coalesce, string, replace and concat for Power Automate workflow expressions. [1]
Encode the value once, in the right order
Add Compose named Encoded_note. Enter this complete expression:
replace(
replace(
replace(
replace(
replace(outputs('Normalised_note'), '&', '&'),
'<', '<'
),
'>', '>'
),
decodeUriComponent('%22'), '"'
),
decodeUriComponent('%27'), '''
)
Nested functions evaluate from the inside out, so the ampersand is replaced first. Replacing it last would encode the ampersands introduced by the other replacements. The two decodeUriComponent calls supply literal quote characters without awkward quote escaping in the expression.
For this fixture, the Compose output should be exactly:
A&B Repairs: <b>urgent</b> — use "side door"; customer's note.
Keep Raw_note and Encoded_note distinct. Do not send the encoded value through the encoder again. If the original text contains the literal characters &, preserving them requires outputting &amp; in HTML source; that is correct for a plain-text source contract.
Add the trusted template after encoding
Add Compose named Email_body with this expression:
concat(
'<h2>Service request</h2>',
'<p><strong>Customer note</strong></p>',
'<p>', outputs('Encoded_note'), '</p>'
)
The heading and paragraph tags belong to the template; the customer note is encoded data. Encoding the entire finished body would make the template tags appear as text as well.
Optionally add Office 365 Outlook → Send an email (V2). Set To to your authorised test address and Subject to Encoding lab — test only. In the Body’s HTML/code view, insert the Outputs token from Email_body. Microsoft documents the editor’s </> control for HTML email content. Designer layouts can differ. [2]
Save and run. Inspect both the Compose output and the received email. The heading should be formatted, while the customer’s <b>urgent</b> should remain visible with its angle brackets. Quotes and the ampersand should look normal. Do not confuse encoded source with rendered text.
<br> markup. Test that extension separately; this lab intentionally uses one line.Test the contract, not just the happy path
| Raw input | Expected result in the email |
|---|---|
A&B |
Literal A&B, without visible entity syntax. |
<b>urgent</b> |
The tags remain visible; the word is not made bold by them. |
5 < 10 > 2 |
Both comparison signs remain visible. |
"quoted" and customer's |
Both quote types remain readable. |
| Null, then an empty string | An empty note paragraph; separate mandatory-field validation decides whether sending is permitted. |
& entered literally |
The literal characters & remain visible, rather than becoming a single ampersand. |
To test null, temporarily change Raw_note to the expression null; for empty text use the expression ''. Restore the fixture afterwards. Also test a long note and accented characters in the Outlook clients your team actually uses. An email client may automatically recognise plain-text URLs; HTML encoding is not a control over every client-side feature.
Recognise the two common failures
The customer’s tags change formatting
Check that Email_body references Encoded_note, not Raw_note. Every plain-text field inserted into hand-built HTML needs its own output encoding.
The email shows entity codes
Check for double encoding or an editor that has treated the finished HTML as plain text. Inspect each Compose output before changing the source data.
Make the boundary an owned control
The process owner defines whether a field is plain text or approved rich text. The flow maintainer owns the encoding step and test cases. The service supervisor confirms the received message remains usable. Keep an approved recipient rule separate from formatting: correct encoding does not authorise disclosure.
When connecting the lab to a form or list, replace only the Raw_note input with the relevant plain-text value, then rerun the tests. Do not decode stored entities indiscriminately or overwrite the original record. Rich-text input needs an explicitly designed sanitisation policy instead of this plain-text contract.
For adoption, show support staff one raw value, one encoded value and the received email. Track formatting defects, avoidable clarification requests and test completion before and after release. These are proposed measures, not promised savings. Recheck when fields, templates or connectors change.
Release-readiness check
Tick only controls supported by evidence. This assessment does not send or store your answers.
Common questions
Does this remove HTML from rich-text fields?
No. It displays markup as literal text. Rich-text sanitisation is a separate design problem.
Can I use this expression for a dynamic link address?
No. A link destination needs its own URL validation and context-appropriate handling. This lab inserts values only as HTML text content.
Why encode the ampersand first?
Later replacements introduce entity strings containing ampersands. Encoding ampersands last would encode those new entities again.
Does a successful flow run prove the email is correct?
No. Inspect intermediate outputs and the received message. Successful execution does not prove that wording, formatting or recipients are correct.
Build business emails people can trust
Smart Statistics helps UK teams turn fragile flows into clear, testable business processes. Bring us the source fields, email template and handover that need to work together.