-
Notifications
You must be signed in to change notification settings - Fork 211
Description
Describe the bug
I am trying to send email with a HTML body. The message is sent, but the resulting HTML renders incorrectly in all the mail clients I have tried (Outlook classic, new Outlook, OWA, Proton). It looks as if the HTML can't interpret the u003c ("<") for some reasons.
The HTML content for the message is good and can be rendered by https://codebeautify.org/htmlviewer
Everything worked until I installed V2.26. Here's an example of a message sent on Wednesday Feb 19 with V2.25.
Expected behavior
I expect the Send-MgUserMail cmdlet to generate valid HTML text in the message body part that can be read by email clients.
How to reproduce
Create HTML content for a message. In this instance, a table is created from some data (could be Get-MgUser)
$SelectedUsers = Get-MgUser -Filter "userType eq 'Member'"
$MsgFrom = '[email protected]'
Define some variables used to construct the HTML content in the message body
HTML header with styles
$HtmlHead="
<style>
BODY{font-family: Arial; font-size: 10pt;}
H1{font-size: 22px;}
H2{font-size: 18px; padding-top: 10px;}
H3{font-size: 16px; padding-top: 8px;}
H4{font-size: 8px; padding-top: 4px;}
</style>"
$HtmlBody = $null
$HtmlBody = $HtmlBody + "
Users
"$HtmlBody = $HtmlBody + ($SelectedUsers| Sort-Object DisplayName | ConvertTo-HTML -Fragment -As Table -PreContent "
Administrative alert: Inactive Teams based on 30-day lookback
")$HtmlBody = $HtmlBody + "
These users are member accounts
"$HtmlBody = $HtmlBody + "
Generated: $(Get-Date -Format 'dd-MMM-yyyy HH:mm')
"$HtmlMsg = $HtmlHead + $HtmlBody + "
"
$MsgSubject = "Member users"
$ToRecipients = @{}
$ToRecipients.Add("emailAddress", @{"address"="[email protected]"} )
[array]$MsgTo = $ToRecipients
Construct the message body
$MsgBody = @{}
$MsgBody.Add('ContentType','html')
$Message = @{}
$Message.Add('subject', $MsgSubject)
$Message.Add('toRecipients', $MsgTo)
$Message.Add('body', $MsgBody)
$Params = @{}
$Params.Add('message', $Message)
$Params.Add('saveToSentItems', $true)
$Params.Add('isDeliveryReceiptRequested', $true)
Send-MgUserMail -UserId $MsgFrom -BodyParameter $Params
SDK Version
V2.26
Latest version known to work for scenario above?
V2.25
Known Workarounds
None
Debug output
Click to expand log
```</details>
### Configuration
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
### Other information
_No response_