Sample code for 30+ languages & platforms
JavaScript

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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

var email = new CkEmail();

success = email.LoadEml("qa_data/eml/happyHour.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

// 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.
    var unpackDir = "qa_output/emails";
    var partsSubdir = "images";
    var htmlFilename = "happyHour.html";
    success = email.UnpackHtml(unpackDir,htmlFilename,partsSubdir);
    if (success !== true) {
        console.log(email.LastErrorText);
        return;
    }

    console.log("Success.");
}