CkPython Requires Chilkat v11.0.0+
CkPython
Read email headers and display the body as text
See more Email Object Examples
Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.
Chilkat CkPython Downloads
import sys
import chilkat
success = False
# Assumes Chilkat is unlocked. See Global Unlock Sample.
email = chilkat.CkEmail()
success = email.LoadEml("with-attachments.eml")
if (success != True):
print(email.lastErrorText())
sys.exit()
print("From: " + email.ck_from())
print("Subject: " + email.subject())
print("Date: " + email.emailDateStr())
i = 0
while (i < email.get_NumTo()) :
print("To: " + email.getToName(i) + " " + email.getToAddr(i))
i = i + 1
referenceId = email.getHeaderField("X-Reference-ID")
if (email.get_LastMethodSuccess() == True):
print("Reference: " + referenceId)
if (email.HasPlainTextBody() == True):
print(email.getPlainTextBody())
else:
if (email.HasHtmlBody() == True):
reader = chilkat.CkHtmlToText()
print(reader.toText(email.getHtmlBody()))
else:
print("No text or HTML body.")