Node.js Requires Chilkat v11.0.0+
Node.js
Read email headers and display the body as text
See more Email Object Examples
Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.
Chilkat Node.js Downloads
NODEJS_PRELUDE
function chilkatExample() {
var success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
var email = new chilkat.Email();
success = email.LoadEml("with-attachments.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
console.log("From: " + email.From);
console.log("Subject: " + email.Subject);
console.log("Date: " + email.EmailDateStr);
var i = 0;
while ((i < email.NumTo)) {
console.log("To: " + email.GetToName(i) + " " + email.GetToAddr(i));
i = i+1;
}
var referenceId = email.GetHeaderField("X-Reference-ID");
if (email.LastMethodSuccess == true) {
console.log("Reference: " + referenceId);
}
if (email.HasPlainTextBody() == true) {
console.log(email.GetPlainTextBody());
}
else {
if (email.HasHtmlBody() == true) {
var reader = new chilkat.HtmlToText();
console.log(reader.ToText(email.GetHtmlBody()));
}
else {
console.log("No text or HTML body.");
}
}
}
chilkatExample();