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

Trace the Received headers on a delivered message

See more Email Object Examples

Each relay prepends its Received field. Read the trace from top to bottom for newest to oldest, and interpret fields in light of the relays you trust. An unsent local draft can have no trace headers.

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

var name = new CkStringBuilder();
var hops = 0;
var i = 0;
while ((i < email.NumHeaderFields)) {
    name.SetString(email.GetHeaderFieldName(i));
    if (name.ContentsEqual("Received",false) == true) {
        hops = hops+1;
        console.log("Hop " + hops + ": " + email.GetHeaderFieldValue(i));
    }

    i = i+1;
}

console.log("Received fields: " + hops);