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

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim wrapper As ChilkatEmail
wrapper.Initialize
success = wrapper.LoadEml("forward-as-attachment.eml")
If success <> True Then
    Log(wrapper.LastErrorText)
    Return
End If

Log("Cover note: " & wrapper.Subject)
If wrapper.NumAttachedMessages = 0 Then
    Log("No attached messages.")
    Return
End If

Dim nested As ChilkatEmail
nested.Initialize
Dim i As Int = 0
Do While (i < wrapper.NumAttachedMessages)
    success = wrapper.GetAttachedEmail(i, nested)
    If success <> True Then
        Log(wrapper.LastErrorText)
        Return
    End If

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