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

Read text and binary MIME parts by content type

See more Email Object Examples

Use the same wildcard and inclusion flags for both counting and retrieval. Request decoded text for textual parts and BinData for binary parts. Use GetAttachedEmail when the goal is to inspect a nested email as a message.

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("workshop.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

var types = "*/*";
var inlineOnly = false;
var excludeAttachments = false;
var count = email.GetNumPartsOfType(types,inlineOnly,excludeAttachments);
var mediaType = new CkStringBuilder();
var i = 0;
while ((i < count)) {
    mediaType.SetString(email.GetNthContentType(i,types,inlineOnly,excludeAttachments));
    if (mediaType.StartsWith("text/",false) == true) {
        var partText = email.GetNthTextPartOfType(i,types,inlineOnly,excludeAttachments);
        if (email.LastMethodSuccess !== true) {
            console.log(email.LastErrorText);
            return;
        }

        console.log(mediaType.GetAsString() + "  " + partText);
    }
    else {
        var data = new CkBinData();
        success = email.GetNthBinaryPartOfTypeBd(i,types,inlineOnly,excludeAttachments,data);
        if (success !== true) {
            console.log(email.LastErrorText);
            return;
        }

        console.log(mediaType.GetAsString() + "  " + data.NumBytes + " bytes");
    }

    i = i+1;
}