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

CkPython
import sys
import chilkat

success = False

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

wrapper = chilkat.CkEmail()
success = wrapper.LoadEml("forward-as-attachment.eml")
if (success != True):
    print(wrapper.lastErrorText())
    sys.exit()

print("Cover note: " + wrapper.subject())
if (wrapper.get_NumAttachedMessages() == 0):
    print("No attached messages.")
    sys.exit()

nested = chilkat.CkEmail()
i = 0
while (i < wrapper.get_NumAttachedMessages()) :
    success = wrapper.GetAttachedEmail(i,nested)
    if (success != True):
        print(wrapper.lastErrorText())
        sys.exit()

    print("Original author: " + nested.ck_from())
    print("Original subject: " + nested.subject())
    print("Files on the original: " + str(nested.get_NumAttachments()))
    i = i + 1