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

List message headers in their original field order

See more Email Object Examples

Walk the top-level header fields by index. Read the name and value at the same index so repeated fields such as Received retain their separate values. Attachment headers belong to the attachment’s MIME part.

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

var i = 0;
while ((i < email.NumHeaderFields)) {
    //  Read the value by index because names can repeat.
    console.log(email.GetHeaderFieldName(i) + ": " + email.GetHeaderFieldValue(i));
    i = i+1;
}