Send-MailMessage converts apostrophe to question mark

This topic contains 4 replies, has 3 voices, and was last updated by  Mahin 3 months, 1 week ago.

  • Author
  • #98097


    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"

  • #98169

    Fredrik Kacsmarck

    A couple of things to try.

    1. Check how the string looks in the variable, is it correct if you do:

    Write-Output $message

    2. Send-Mailmessage also has an Encoding parameter, so try:

    Send-mailmessage -To -From -smtpserver "" -subject "Test email" -Body $message -Encoding utf8
    • #98304


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

  • #98187

    Joel Sallow

    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. 🙂

    • #98307


      Joel, thank you much for your reply as well 🙂

You must be logged in to reply to this topic.