3

Im sending a testemail via powershell like

$messageParameters = @{
    Subject    = "Email Tool"
    Body       = Get-Content "C:\body.txt" | out-string
    From       = "Info <[email protected]>"
    To         = "Me <[email protected]>"
    SmtpServer = "mail.xy.de"
    Encoding   = New-Object System.Text.UTF8Encoding
}

send-mailmessage @messageParameters -BodyAsHtml

everything is working find except the encoding.

if i don't use encoding some characters are send as ??

and if i use it, what i actually want to do, than i get this Ä Ö Ü

but it should be ä ö ü and not this above.

If i don't send the mail as HTML it works.

How can i send the mail with the right encoding AND as html ?

1 Answer 1

4

I believe the problem is that your text-file is getting jumbled when you are reading it into a variable as non-utf8.

I would try getting the text file as UTF-8 and keeping the Encoding line.

Body = Get-Content "C:\body.txt" -Encoding UTF8 | Out-String

EDIT: Added Out-String per Dwza.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you very much! this was exact what i was looking for :D
@Dwza, Yea, good catch. I sometimes forget that Powershell usually returns objects. Edited my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.