Send-MailMessage converts apostrophe to question mark

Hi folks. I’m trying to setup sending emails via PowerShell and have the code to do it, but every time i use Send-MailMessage to send the body, it converts apostrophe symbol to question mark. Can someone advise what i’m doing wrong? I tried to convert it to UTF8 and ASCII but that made it worse. Thank you

$message = get-content c:\mail\sample.txt | out-string

Send-mailmessage -To -From -smtpserver “” -subject “Test email” -Body $message

The sample.txt file in c:\temp has the correct message format like this below

“Please don’t send out wrong requests for support”

But once i execute the PS script, and get the email, it is written incorrectly as below

“Please don?t send out wrong requests for support”

A couple of things to try.

  1. Check how the string looks in the variable, is it correct if you do:
Write-Output $message
  1. Send-Mailmessage also has an Encoding parameter, so try:
Send-mailmessage -To -From -smtpserver "" -subject "Test email" -Body $message -Encoding utf8

Hmm. Instead of using Out-String, try simply supplying the -Raw parameter to Get-Content to import the file as a single block of text and see if that clears things up a bit for you. :slight_smile:

Hi Fredrik, it looks like your solution of adding -encoding UTF8 at the end did the trick :slight_smile: Thanks so much!

Joel, thank you much for your reply as well :slight_smile: