JavaScript Requires Chilkat v11.0.0+
JavaScript
Convert image data URLs to related MIME parts
See more Email Object Examples
Start with HTML that contains image bytes in a data URL. Convert it to conventional CID references and inspect the resulting related-item count before saving.
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.SetHtmlBody("<html><body><p>Registration confirmed.</p><img src=\"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==\" alt=\"Mark\"></body></html>");
success = email.ConvertInlineImages();
if (success !== true) {
console.log(email.LastErrorText);
return;
}
console.log("Related images: " + email.NumRelatedItems);
console.log(email.GetHtmlBody());
success = email.SaveEml("related-images.eml");
if (success !== true) {
console.log(email.LastErrorText);
return;
}
console.log("Saved related-images.eml.");