Sample code for 30+ languages & platforms
VBScript 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 VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

set wrapper = CreateObject("Chilkat.Email")
success = wrapper.LoadEml("forward-as-attachment.eml")
If (success <> 1) Then
    outFile.WriteLine(wrapper.LastErrorText)
    WScript.Quit
End If

outFile.WriteLine("Cover note: " & wrapper.Subject)
If (wrapper.NumAttachedMessages = 0) Then
    outFile.WriteLine("No attached messages.")
    WScript.Quit
End If

set nested = CreateObject("Chilkat.Email")
i = 0
Do While (i < wrapper.NumAttachedMessages)
    success = wrapper.GetAttachedEmail(i,nested)
    If (success <> 1) Then
        outFile.WriteLine(wrapper.LastErrorText)
        WScript.Quit
    End If

    outFile.WriteLine("Original author: " & nested.From)
    outFile.WriteLine("Original subject: " & nested.Subject)
    outFile.WriteLine("Files on the original: " & nested.NumAttachments)
    i = i + 1
Loop

outFile.Close