SCRT-HQ / PSGSuite

Powershell module for Google / G Suite API calls wrapped in handy functions. Authentication is established using a service account via P12 key to negate the consent popup and allow for greater handsoff automation capabilities
https://psgsuite.io/
Apache License 2.0
234 stars 68 forks source link

Send-GmailMessage: Special characters not displayed as expected in HTML Body #361

Open sjbruni opened 2 years ago

sjbruni commented 2 years ago

I'm trying to send a message using the function "send-gmailmessage" with attribute "-bodyashtml", and of course using HTML format in the body. The issue is that when the message is received, the special characters like "ñ" and "ó" (the message is in Spanish), are not shown correctly.

For example show like "ñ" instead of "ñ" or "ó" instead of "ó"

I tried with the meta into the HTML:

But not working (of course tried also with "UTF-8" instead of "ISO-8859-1")

The powershell command line I'm using is:

Send-GmailMessage -From xxxx@yyy.edu.ar -Subject "Test email sending" -Body $htmlContent -BodyAsHtml -To "xxxx.yyyy@gmail.com" -Attachments "[Path of the file to been attached]"

francocatto commented 9 months ago

I had the same issue. And I founded that the broken special characters in UTF-8 is generated by the missuse of the toString() for serializing the message with the C# class MimeKit.MimeMessage. Here the author of the lib explain why you shouldn't use this: https://github.com/jstedfast/MimeKit/issues/554

MimeKit.MimeMessage is called from Send-GmailMessage on line: $raw = New-MimeMessage @messageParams | Convert-Base64 -From NormalString -To WebSafeBase64String