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

Offer plain-text and HTML versions of the same message

See more Email Object Examples

Put the same information in two MIME alternatives. A mail reader chooses a representation it supports. Use descriptive link text in HTML and include the destination URL in plain text.

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 registration";
//  Both alternatives describe the same invitation.
success = email.AddPlainTextAlternativeBody("Register for the workshop at https://example.com/workshops");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

success = email.AddHtmlAlternativeBody("<p><a href='https://example.com/workshops'>Register for the workshop</a></p>");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

success = email.SaveEml("alternatives.eml");
if (success !== true) {
    console.log(email.LastErrorText);
    return;
}

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