JavaScript Requires Chilkat v11.0.0+
JavaScript
Add files to a draft as attachments
See more Email Object Examples
Use explicit MIME types for a PDF agenda and an XML schedule. Filenames are relative to the application working directory. Save after both files have been added so a missing file does not leave a partially prepared draft.
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";
email.Body = "The agenda and machine-readable schedule are attached.";
success = email.AddFileAttachment2("agenda.pdf","application/pdf");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
success = email.AddFileAttachment2("schedule.xml","application/xml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
console.log("Attachments in draft: " + email.NumAttachments);
success = email.SaveEml("attachments.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
console.log("Saved attachments.eml.");