What is correct Encoding for Scandinavin characters to Outlook 365 ?

MikroMike 1 Reputation point
2022-09-15T08:28:20.663+00:00

Hello

$PSDefaultParameterValues['*:Encoding'] = 'utf8'

$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)

Encoding = New-Object System.Text.UTF8Encoding

$Mail.To = "receiver@something .email"
$Mail.Cc = "copytome@something .email"
$Mail.importance = 2
$Mail.Subject = "komentoriviltä lähetetty"
$Mail.Body ="liitetiedostossa koodi, "
$Mail.Attachments.add("C:\Users\X\Desktop\test123.txt")

$Mail.Send()

Script works and sends email via powershell.

Question is: what should be encoding for scandinavian characters ?
in this line: $PSDefaultParameterValues['*:Encoding'] = 'utf8' <-----------

Thanks Mike.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,766 Reputation points
    2022-09-16T09:17:38.237+00:00

    Hello

    Thank you for your question and reaching out. I can understand you are having query related to UFT in Email

    For best overall compatibility, avoid using BOMs in UTF-8 files. Unix platforms and Unix-heritage utilities also used on Windows Platforms don't support BOMs.

    PowerShell defaults to utf8NoBOM for all output.

    Reference

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_character_encoding?view=powershell-7.2

    -------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  2. Rich Matheisen 47,901 Reputation points
    2022-09-16T16:10:53.28+00:00

    UTF8 would be the correct encoding. However, actually displaying the information correctly depends on the code page and font in use at the time.

    For Scandinavian countries I think the code page 1252 (for many European countries). If the characters aren't displaying correctly, check the current code page by using the "chcp" DOS command. You may find that it's set to "437".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.