JavaScript Requires Chilkat v11.0.0+
JavaScript
Combine alternatives, a related image, and an attachment
See more Email Object Examples
Compose a single draft with a plain-text fallback, an HTML invitation that references a local logo, and a downloadable agenda. Chilkat builds the related, alternative, and mixed MIME containers. Supply logo.png and agenda.pdf in the working directory.
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();
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";
success = email.AddPlainTextAlternativeBody("Join our workshop. The agenda is attached.");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
success = email.AddHtmlAlternativeBody("<p><img src='logo.png' alt='Workshop team'></p><p>The agenda is attached.</p>");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
// Match the filename used in the HTML to the related file on disk.
success = email.AddRelatedFile2("logo.png","logo.png");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
success = email.AddFileAttachment2("agenda.pdf","application/pdf");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
success = email.SaveEml("workshop.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
console.log("Saved workshop.eml.");