Sample code for 30+ languages & platforms
PowerShell Requires Chilkat v11.0.0+

Read email headers and display the body as text

See more Email Object Examples

Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

$email = New-Object Chilkat.Email
$success = $email.LoadEml("with-attachments.eml")
if ($success -ne $true) {
    $($email.LastErrorText)
    exit
}

$("From: " + $email.From)
$("Subject: " + $email.Subject)
$("Date: " + $email.EmailDateStr)
$i = 0
while (($i -lt $email.NumTo)) {
    $("To: " + $email.GetToName($i) + "  " + $email.GetToAddr($i))
    $i = $i + 1
}

$referenceId = $email.GetHeaderField("X-Reference-ID")
if ($email.LastMethodSuccess -eq $true) {
    $("Reference: " + $referenceId)
}

if ($email.HasPlainTextBody() -eq $true) {
    $($email.GetPlainTextBody())
}
else {
    if ($email.HasHtmlBody() -eq $true) {
        $reader = New-Object Chilkat.HtmlToText
        $($reader.ToText($email.GetHtmlBody()))
    }
    else {
        $("No text or HTML body.")
    }

}