Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd HTML output from Send-MgUserMail (V2.26) #3160

Open
12Knocksinna opened this issue Feb 21, 2025 · 2 comments
Open

Odd HTML output from Send-MgUserMail (V2.26) #3160

12Knocksinna opened this issue Feb 21, 2025 · 2 comments
Assignees
Labels
Bug - P1 type:bug A broken experience

Comments

@12Knocksinna
Copy link

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.

Image

The HTML content for the message is good and can be rendered by https://codebeautify.org/htmlviewer

Image

Everything worked until I installed V2.26. Here's an example of a message sent on Wednesday Feb 19 with V2.25.

Image

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('Content', "$($HtmlMsg)")
$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

Image

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_
@12Knocksinna 12Knocksinna added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Feb 21, 2025
@12Knocksinna
Copy link
Author

I reverted to V2.25 and the code runs as expected.

@nathan-mhk
Copy link

I'm having this issue as well. All symbols are escaped to unicode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug - P1 type:bug A broken experience
Projects
None yet
Development

No branches or pull requests

3 participants