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 firstname.lastname@example.org -From email@example.com -smtpserver “18.104.22.168” -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.
- Check how the string looks in the variable, is it correct if you do:
- Send-Mailmessage also has an Encoding parameter, so try:
Send-mailmessage -To firstname.lastname@example.org -From email@example.com -smtpserver "22.214.171.124" -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.
Hi Fredrik, it looks like your solution of adding -encoding UTF8 at the end did the trick Thanks so much!
Joel, thank you much for your reply as well