Unicode C++ Requires Chilkat v11.0.0+
Unicode 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 Unicode C++ Downloads
#include <CkEmailW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkEmailW email;
success = email.LoadEml(L"with-attachments.eml");
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
CkEmailW preview;
success = email.MakeCopy(preview);
if (success != true) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
// Keep related items: the HTML still refers to them.
preview.DropAttachments();
wprintf(L"Files in original: %d Files in preview: %d\n",email.get_NumAttachments(),preview.get_NumAttachments());
if (preview.HasHtmlBody() != true) {
wprintf(L"This message has no HTML preview.\n");
return;
}
CkStringBuilderW html;
success = preview.GetHtmlBodySb(true,html);
if (success != true) {
wprintf(L"%s\n",preview.lastErrorText());
return;
}
success = html.WriteFile(L"preview.html",L"utf-8",false);
if (success != true) {
wprintf(L"Failed: html.WriteFile.\n");
return;
}
wprintf(L"Saved preview.html.\n");
}