Sample code for 30+ languages & platforms
JavaScript Requires Chilkat v11.0.0+

Build a text/watch-html alternative

See more Email Object Examples

Reproduce the three-part layout used by a legacy Watch email integration. Readers can choose plain text or standard HTML when they do not recognize the specialist part. This example demonstrates the MIME layout without assuming current device behavior.

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;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

var email = new CkEmail();
email.From = "Workshop team <events@example.com>";
success = email.AddTo("Alex Rivera","alex@example.net");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

email.Subject = "Workshop reminder";
email.Body = "Your workshop starts at 09:00.";
var mimeBytes = new CkBinData();
success = email.GetMimeBd(mimeBytes);
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

var mime = new CkMime();
success = mime.LoadMimeBd(mimeBytes);
if (success !== true) {
    console.log(mime.LastErrorText);
    return;
}

success = mime.ConvertToMultipartAlt();
if (success !== true) {
    console.log(mime.LastErrorText);
    return;
}

//  Append the specialist part before the standard HTML fallback.
var special = new CkMime();
special.ContentType = "text/watch-html";
special.Charset = "utf-8";
special.SetBody("<b>Workshop at 09:00</b>");
success = mime.AppendPart(special);
if (success !== true) {
    console.log(mime.LastErrorText);
    return;
}

var standard = new CkMime();
standard.ContentType = "text/html";
standard.Charset = "utf-8";
standard.SetBody("<p>Your workshop starts at <b>09:00</b>.</p>");
success = mime.AppendPart(standard);
if (success !== true) {
    console.log(mime.LastErrorText);
    return;
}

success = mime.SaveMime("watch.eml");
if (success !== true) {
    console.log(mime.LastErrorText);
    return;
}

console.log("Saved watch.eml.");