Sample code for 30+ languages & platforms
Chilkat2-Python

Access Attached Message (Embedded Email)

How to access an email embedded within another email (i.e. an attached message).

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

email = chilkat2.Email()

# Load an email from a .eml
success = email.LoadEml("embeddedEmail.eml")
if (success == False):
    print(email.LastErrorText)
    sys.exit()

# Display how many attached emails are embedded within
# this one:
numAttached = email.NumAttachedMessages
print("numAttached = " + str(numAttached))

# Get the 1st attached message.
email2 = chilkat2.Email()
success = email.GetAttachedEmail(0,email2)
if (success == True):

    # Display the subject, From, and a header field...
    print(email2.Subject)
    print(email2.From)
    print(email2.GetHeaderField("X-SOMETHING"))