Skip to content

Send-MgUserMail fails formatting html-encoded mails since 2.26.0 #3180

@pbo-top

Description

@pbo-top

Describe the bug

When calling Send-MgUserMail from Microsoft.Graph.Users.Actions 2.26.0 with content-type "html" the sent email contains unicode-like codes instead of the given html-tags. The code was running nicely with 2.25.0.
Characters such as: '
in the subject line also get garbled to some codes.

Mail sample:
Image

Expected behavior

Same code running but in 2.25.0, mail sample:

Image

How to reproduce

snippet of code:
`
$contenttype = "html"
$saveInSend = "true"

# Read the mail template from file
$mailTemplate = Get-Content "./body.html" -Raw


   $mailBody = $mailTemplate

    foreach ($property in $appRegSinner.PSObject.Properties) {
        $placeholder = "#{0}#" -f $property.Name
        $mailBody = $mailBody.Replace($placeholder, $property.Value)
    }
    
    $subject = "Registrering af Azure Application '$($appRegSinner.appName)' i ServiceNow"

    # Override the mail receiver address if specified
    $override = $overrideMailReceiverAddress.TrimEnd()
    if ($override -ne "none") {
        $appRegSinner.to = $overrideMailReceiverAddress
    }

    $params = @{
        Message = @{
            Subject = $subject
            Body    = @{
                ContentType = $contenttype
                Content     = $mailBody
            }
            ToRecipients = @(
                @{
                    EmailAddress = @{
                        Address = $appRegSinner.to
                    }
                }
            )
            CcRecipients = @(
                @{
                    EmailAddress = @{
                        Address = $appRegSinner.cc
                    }
                }
            )
        }
        SaveToSentItems = $saveInSend
    }
    
    Write-Information "Sending mail to $($appRegSinner.to)"
    $params | ConvertTo-Json -Depth 5 | Write-Information

    Send-MgUserMail -UserId $appRegSinner.from -BodyParameter $params

`

snippet of body.html
`
Du har oprettet denne Enterprise Application i Azure:

Navn: #appName#
AppID: #appId#

Den manglede at blive registreret i ServiceNow CMDB'en. Me... `

SDK Version

2.26.0

Latest version known to work for scenario above?

2.25.0

Known Workarounds

Force usage of 2.25.0 modules all around.

Debug output

Click to expand log ```
</details>


### Configuration

OS: Windows + Ubuntu
Powershell: 7.5.0

### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions