How to stop Azure Logic Apps from turning your HTTPS link into a mailto link?
It's December, Mariah Carey is gathering her royalty cheques and I'm here dealing with Logic Apps turning my HTTPS links into mailto links.
Yep - this one has all the right ingredients: something that should be trivial, an editor trying to be helpful, an inexplicable mailto:, and a workaround that's slightly ridiculous but actually makes sense once you know what's happening. So a typical day in the life of Yours Truly.
I was building an Azure Monitor alert workflow in Azure Logic Apps. The workflow receives the Azure Monitor Common Alert Schema, parses it, and posts a notification to Microsoft Teams.
Pretty standard stuff.
Problem
My post to the Teams channel needed to have a link to the Azure Portal investigation page for the alert. An easy requirement to fill, right?
When using the Common Alert Schema, Azure helpfully provides an investigationLink in the alert payload. The value looks approximately like this:
https://portal.azure.com/#view/Microsoft_Azure_Monitoring_Alerts/Investigate.ReactView/alertId/...
Excellent! All I need is a nice link in the Teams message:
<a href="@{body('Parse_JSON')?['data']?['essentials']?['investigationLink']}">
🔎 Open alert in Azure Portal
</a>
Save the Logic App.
And...
Nope!
Logic Apps decides that my perfectly respectable hyperlink clearly wants to be an email address.
The resulting link becomes something like:
mailto:https://portal.azure.com/#view/...
Thanks, I hate it.

Reason
So what's actually happening?
The important discovery was that Teams isn't the one doing this.
Yep - for once, Teams is not the culprit here.
The problem is born already when the Logic Apps action is saved.
See, if an anchor's href contains only a dynamic expression:
<a href="@{body('Parse_JSON')?...}"> ...
Logic Apps is trying to help you by "fixing" the protocol that you clearly just forgot.
Even though that expression evaluates at runtime to a perfectly valid https:// URL, Logic Apps can't see a protocol in the literal value while you're editing/saving the action.
So it helpfully adds one.
Unfortunately for you, the protocol it chooses is:
mailto:
Yep. Even when posting to a Teams channel.
A totally sensible default option, right? 🫠

This means we need Logic Apps to see https: when the workflow is saved (or it'll mangle the link), while still using the URL Azure Monitor gives us.
(The slightly stupid) Solution
Well, at least it's an easy fix.
My Azure Monitor payload already contains:
data.essentials.investigationLink
So I added it to the Parse JSON schema:
"investigationLink": {
"type": "string"
}
Then I added a Compose action:
@replace(
body('Parse_JSON')?['data']?['essentials']?['investigationLink'],
'https:',
''
)
So, for example:
https://portal.azure.com/#view/...
becomes:
//portal.azure.com/#view/...
Now, why would I deliberately break a perfectly good URL?
Well, because now I can construct the hyperlink like this:
<a href="https:@{outputs('Compose')}">
🔎 Open alert in Azure Portal
</a>
So Logic Apps sees:
https:
and is satisfied. No helpful mailto: appears.
At runtime, the Compose output gets appended:
https:
+
//portal.azure.com/#view/...
And we're back to:
https://portal.azure.com/#view/...
Beautiful? No.
Functional? Yes.
Why not construct the Azure Portal URL manually?
I originally considered generating the URL from alertId. That's possible, and not really that difficult to get working.
But there's a reason I didn't.
Azure Monitor already gives you investigationLink, and in my case it uses the Microsoft_Azure_Monitoring_Alerts/Investigate.ReactView route. Reconstructing a different Portal URL yourself introduces another dependency on Azure Portal's internal routing for absolutely no benefit.
Use the URL Microsoft provides. Just temporarily deform its protocol to appease Logic Apps.
The takeaway
If an Azure Logic Apps action containing HTML mysteriously changes your dynamic HTTPS hyperlink into:
mailto:https://...
check whether the href starts entirely with dynamic content.
If it does, my simple workaround is:
- Take the actual URL returned by your API or trigger.
- Strip
https:from it (using Compose, for example). - Put
https:literally (and statically) into thehref. - Append the remainder dynamically.
- Question the life choices that led you here.
In my case:
href="https:@{outputs('Compose')}"
did the trick. The things we do to appease hyperlink validators...
Whoever wrote the spec for dynamic content handling in href attributes laughed all the way to the bank. But with the workaround, at least their decisions won't mess with your users anymore! 🥲
Comments
No comments yet.