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

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat PowerShell Downloads

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

$success = $false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

$wrapper = New-Object Chilkat.Email
$success = $wrapper.LoadEml("forward-as-attachment.eml")
if ($success -ne $true) {
    $($wrapper.LastErrorText)
    exit
}

$("Cover note: " + $wrapper.Subject)
if ($wrapper.NumAttachedMessages -eq 0) {
    $("No attached messages.")
    exit
}

$nested = New-Object Chilkat.Email
$i = 0
while (($i -lt $wrapper.NumAttachedMessages)) {
    $success = $wrapper.GetAttachedEmail($i,$nested)
    if ($success -ne $true) {
        $($wrapper.LastErrorText)
        exit
    }

    $("Original author: " + $nested.From)
    $("Original subject: " + $nested.Subject)
    $("Files on the original: " + $nested.NumAttachments)
    $i = $i + 1
}