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

Create an HTML preview with embedded images

See more Email Object Examples

Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.

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
}

$preview = New-Object Chilkat.Email
$success = $email.MakeCopy($preview)
if ($success -ne $true) {
    $($email.LastErrorText)
    exit
}

#  Keep related items: the HTML still refers to them.
$preview.DropAttachments()
$("Files in original: " + $email.NumAttachments + "  Files in preview: " + $preview.NumAttachments)
if ($preview.HasHtmlBody() -ne $true) {
    $("This message has no HTML preview.")
    exit
}

$html = New-Object Chilkat.StringBuilder
$success = $preview.GetHtmlBodySb($true,$html)
if ($success -ne $true) {
    $($preview.LastErrorText)
    exit
}

$success = $html.WriteFile("preview.html","utf-8",$false)
if ($success -ne $true) {
    $("Failed: html.WriteFile.")
    exit
}

$("Saved preview.html.")