Sample code for 30+ languages & platforms
Chilkat2-Python

Unpack HTML Email to Files

Unpacks an HTML email into an HTML file and related files (images and style sheets). The links within the HTML are updated to point to the files unpacked and saved to disk.

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

email = chilkat2.Email()

success = email.LoadEml("qa_data/eml/happyHour.eml")
if (success != True):
    print(email.LastErrorText)
    sys.exit()

# Is this an HTML email?
if (email.HasHtmlBody() == True):

    # Unpack the HTML to files.  The image and css URLs
    # in the HTML are modified to point to the files extracted to disk.
    unpackDir = "qa_output/emails"
    partsSubdir = "images"
    htmlFilename = "happyHour.html"
    success = email.UnpackHtml(unpackDir,htmlFilename,partsSubdir)
    if (success != True):
        print(email.LastErrorText)
        sys.exit()

    print("Success.")