Sample code for 30+ languages & platforms
JavaScript

Access Attached Message (Embedded Email)

How to access an email embedded within another email (i.e. an attached 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;

var email = new CkEmail();

// Load an email from a .eml
success = email.LoadEml("embeddedEmail.eml");
if (success == false) {
    console.log(email.LastErrorText);
    return;
}

// Display how many attached emails are embedded within
// this one:
var numAttached = email.NumAttachedMessages;
console.log("numAttached = " + numAttached);

// Get the 1st attached message.
var email2 = new CkEmail();
success = email.GetAttachedEmail(0,email2);
if (success == true) {

    // Display the subject, From, and a header field...
    console.log(email2.Subject);
    console.log(email2.From);
    console.log(email2.GetHeaderField("X-SOMETHING"));
}