Node.js Requires Chilkat v11.0.0+
Node.js
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.
Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var wrapper = new chilkat.Email();
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 chilkat.Email();
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;
}
}
chilkatExample();