JavaScript Requires Chilkat v11.0.0+
JavaScript
Read an attached email
See more Email Object Examples
Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.
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.
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var wrapper = new CkEmail();
success = wrapper.LoadEml("forward-as-attachment.eml");
if (success !== true) {
console.log(wrapper.LastErrorText);
return;
}
console.log("Cover note: " + wrapper.Subject);
if (wrapper.NumAttachedMessages == 0) {
console.log("No attached messages.");
return;
}
var nested = new CkEmail();
var i = 0;
while ((i < wrapper.NumAttachedMessages)) {
success = wrapper.GetAttachedEmail(i,nested);
if (success !== true) {
console.log(wrapper.LastErrorText);
return;
}
console.log("Original author: " + nested.From);
console.log("Original subject: " + nested.Subject);
console.log("Files on the original: " + nested.NumAttachments);
i = i+1;
}