Sample code for 30+ languages & platforms
JavaScript Requires Chilkat v11.0.0+

Export HTML with related images embedded as data URLs

See more Email Object Examples

Read inline-image.eml and produce a single UTF-8 HTML file with its related images embedded. This is useful for a self-contained preview. Treat HTML from received mail as untrusted when displaying it.

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;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

var email = new CkEmail();
success = email.LoadEml("inline-image.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

if (email.HasHtmlBody() !== true) {
    console.log("This message has no HTML body.");
    return;
}

var html = new CkStringBuilder();
success = email.GetHtmlBodySb(true,html);
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

success = html.WriteFile("preview.html","utf-8",false);
if (success !== true) {
    console.log("Failed: html.WriteFile.");
    return;
}

console.log("Saved preview.html.");