Sending email containing accent with powershell

我怕爱的太早我们不能终老 提交于 2020-01-17 07:22:25

问题


I'm trying to send emails containing accents via powershell.

If i do the following :

$enc = [System.Text.Encoding]::UTF8
Send-MailMessage -to "Recipient@company.com" -from "Sender@company.com" -subject "test" -body "éèà" -Encoding $enc

It actually works and i get the accents fine in the mail.

BUT, if i do this :

$enc = [System.Text.Encoding]::UTF8

$Body = @"

éèà

"@

Send-MailMessage -to "Recipient@company.com" -from "Sender@company.com" -subject "test" -body $body -Encoding $enc

The email looks like this : éèÃ

I actually need to use the @" "@ quotes to send multiple lines mails.

Does anybody have a clue of how i could make this work ?

Thanks for your help !


回答1:


please try to execute this prior to your script :

$OutputEncoding = [Console]::OutputEncoding


来源:https://stackoverflow.com/questions/21454096/sending-email-containing-accent-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!