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 <C_CkEmailW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmailW email;
HCkEmailW preview;
HCkStringBuilderW html;
success = FALSE;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email = CkEmailW_Create();
success = CkEmailW_LoadEml(email,L"with-attachments.eml");
if (success != TRUE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkEmailW_Dispose(email);
return;
}
preview = CkEmailW_Create();
success = CkEmailW_MakeCopy(email,preview);
if (success != TRUE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(email));
CkEmailW_Dispose(email);
CkEmailW_Dispose(preview);
return;
}
// Keep related items: the HTML still refers to them.
CkEmailW_DropAttachments(preview);
wprintf(L"Files in original: %d Files in preview: %d\n",CkEmailW_getNumAttachments(email),CkEmailW_getNumAttachments(preview));
if (CkEmailW_HasHtmlBody(preview) != TRUE) {
wprintf(L"This message has no HTML preview.\n");
CkEmailW_Dispose(email);
CkEmailW_Dispose(preview);
return;
}
html = CkStringBuilderW_Create();
success = CkEmailW_GetHtmlBodySb(preview,TRUE,html);
if (success != TRUE) {
wprintf(L"%s\n",CkEmailW_lastErrorText(preview));
CkEmailW_Dispose(email);
CkEmailW_Dispose(preview);
CkStringBuilderW_Dispose(html);
return;
}
success = CkStringBuilderW_WriteFile(html,L"preview.html",L"utf-8",FALSE);
if (success != TRUE) {
wprintf(L"Failed: html.WriteFile.\n");
CkEmailW_Dispose(email);
CkEmailW_Dispose(preview);
CkStringBuilderW_Dispose(html);
return;
}
wprintf(L"Saved preview.html.\n");
CkEmailW_Dispose(email);
CkEmailW_Dispose(preview);
CkStringBuilderW_Dispose(html);
}