JavaScript Requires Chilkat v11.0.0+
JavaScript
Read the plain-text and HTML bodies separately
See more Email Object Examples
When both alternatives exist, Body returns HTML. Use the explicit body accessors to choose text for an index or HTML for a viewer. This example reads alternatives.eml from the previous example.
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 email = new CkEmail();
success = email.LoadEml("alternatives.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
// A message can have either representation, both, or neither.
if (email.HasPlainTextBody() == true) {
console.log("Plain text: " + email.GetPlainTextBody());
}
if (email.HasHtmlBody() == true) {
console.log("HTML source: " + email.GetHtmlBody());
}
if ((email.HasPlainTextBody() == false) && (email.HasHtmlBody() == false)) {
console.log("No text or HTML body. Inspect the MIME parts.");
}