C# Requires Chilkat v11.0.0+
C#
Create an HTML preview with embedded images
See more Email Object Examples
Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.
Chilkat C# Downloads
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Chilkat.Email email = new Chilkat.Email();
success = email.LoadEml("with-attachments.eml");
if (success != true) {
Debug.WriteLine(email.LastErrorText);
return;
}
Chilkat.Email preview = new Chilkat.Email();
success = email.MakeCopy(preview);
if (success != true) {
Debug.WriteLine(email.LastErrorText);
return;
}
// Keep related items: the HTML still refers to them.
preview.DropAttachments();
Debug.WriteLine("Files in original: " + Convert.ToString(email.NumAttachments) + " Files in preview: " + Convert.ToString(preview.NumAttachments));
if (preview.HasHtmlBody() != true) {
Debug.WriteLine("This message has no HTML preview.");
return;
}
Chilkat.StringBuilder html = new Chilkat.StringBuilder();
success = preview.GetHtmlBodySb(true,html);
if (success != true) {
Debug.WriteLine(preview.LastErrorText);
return;
}
success = html.WriteFile("preview.html","utf-8",false);
if (success != true) {
Debug.WriteLine("Failed: html.WriteFile.");
return;
}
Debug.WriteLine("Saved preview.html.");