Aug 16 2024 01:43 AM
Dear community
A third-party monitoring application creates static adaptive cards when an alert is triggered.
This application calls a PowerShell script and provides a couple parameters including the adaptive card json.
I have now tried to pack this adaptive card into a html email and send it via Graph API.
Sadly I cannot get it to render the adaptive card for example in Outlook.
HTML message
<html>
<head>
<metahttp-equiv="Content-Type"content="text /html;charset=utf-8">
<scripttype='application /adaptivecard+json'>
{"type":"AdaptiveCard","version":"1.4","hideOriginalBody":true,"body":[{...}]}
</script>
</head>
<body> </body>
</html>
Graph Mail
$emailRecipients = @(
'email address removed for privacy reasons'
)
[array]$toRecipients = ConvertTo-IMicrosoftGraphRecipient -SmtpAddresses $emailRecipients
$emailSender = 'email address removed for privacy reasons'
$emailSubject = "Sample Email AdaptiveCard"
$emailBody = @{
ContentType = 'html'
Content = Get-Content -Path 'C:\...\adaptivecard.html'
}
$body += @{subject = $emailSubject}
$body += @{toRecipients = $toRecipients}
$body += @{body = $emailBody}
$bodyParameter += @{'message' = $body}
$bodyParameter += @{'saveToSentItems' = $false}
Send-MgUserMail -UserId $emailSender -BodyParameter $bodyParameter
I am grateful for any advice or help with this problem.
Many thanks
Simon