This topic contains 3 replies, has 2 voices, and was last updated by
July 17, 2014 at 10:22 pm #17252
Hey, hope someone can give me some advice on a weird issue i've encountered.
I'm trying to send emails that contains swedish symbols using send-mailmessage in powershell 4.0. This works as intended when I run the command in a powershell console window but when I run the same cmdlet in a .ps1 file the swedish characters turn to gibberish.
Send-MailMessage -subject 'Testing special characters: Å Ä Ö' -Body 'testing Å Ä Ö åäö' -to $to -from $from -encoding UTF7 -smtpserver $smtpserver
The resulting mail when ran in ps1 file has the following body:
testing Ã…Ã„Ã– Ã¥Ã¤Ã¶
I then tried the .ps1 file on a win2008R2 server that has powershell 3.0 installed, and from this machine the email arrived correctly formatted.
Have I encountered a bug in PS 4.0 or am I missing something obvious here?
July 18, 2014 at 3:46 am #17262ParticipantPoints: 0Rank: Member
I can't seem to replicate your issue using a .ps1 file with the following
Send-MailMessage -subject 'Testing special characters: Å Ä Ö' -Body 'testing Å Ä Ö åäö' -To $email -From $email -Encoding utf7 -SmtpServer $smtpserver -Credential (Get-Credential)
I tried saving the .ps1 file in different encoding formats (ANSI/Unicode/UTF8) but no hieroglyphs.
Perhaps something else in your script is causing the characters to get garbled?
July 18, 2014 at 4:18 am #17263
Thanks Martin, I tried it on a windows 2012 r2 server with 4.0 installed and can't replicate it there either.
That line is all my script file contains at the moment in order to make sure there was nothing else that could cause this.
I'll run this script from the 2012 server but it makes me frustrated when I can't figure out why it's working differently on my client 🙂
July 18, 2014 at 4:29 am #17264
Solved, I was using Notepad++ to save this file. Notepad++ was set to save as encoding "ANSI as UTF-8", when I changed this to UTF-8 it works perfectly. D'oh!
The topic ‘Send-MailMessage encoding issue in Powershell 4.0’ is closed to new replies.