JavaScript Requires Chilkat v11.0.0+
JavaScript
Embed an image supplied as base64
See more Email Object Examples
Decode the base64 payload into binary data and attach it as a related image. This small GIF makes the example self-contained. Substitute your own image data and a matching filename.
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";
var image = new CkBinData();
success = image.AppendEncoded("R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==","base64");
if (success !== true) {
console.log("Failed: image.AppendEncoded.");
return;
}
email.SetHtmlBody("<p>Registration confirmed.</p><img src='mark.gif' alt='Confirmation mark'>");
// Chilkat connects the HTML reference to a related MIME part.
success = email.AddRelatedBd2(image,"mark.gif");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
success = email.SaveEml("inline-image.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
console.log("Saved inline-image.eml.");