Unicode C Requires Chilkat v11.0.0+
Unicode C
Read email headers and display the body as text
See more Email Object Examples
Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.
Chilkat Unicode C Downloads
#include <C_CkEmailW.h>
#include <C_CkHtmlToTextW.h>
void ChilkatSample(void)
{
BOOL success;
HCkEmailW email;
int i;
const wchar_t *referenceId;
HCkHtmlToTextW reader;
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;
}
wprintf(L"From: %s\n",CkEmailW_ck_from(email));
wprintf(L"Subject: %s\n",CkEmailW_subject(email));
wprintf(L"Date: %s\n",CkEmailW_emailDateStr(email));
i = 0;
while ((i < CkEmailW_getNumTo(email))) {
wprintf(L"To: %s %s\n",CkEmailW_getToName(email,i),CkEmailW_getToAddr(email,i));
i = i + 1;
}
referenceId = CkEmailW_getHeaderField(email,L"X-Reference-ID");
if (CkEmailW_getLastMethodSuccess(email) == TRUE) {
wprintf(L"Reference: %s\n",referenceId);
}
if (CkEmailW_HasPlainTextBody(email) == TRUE) {
wprintf(L"%s\n",CkEmailW_getPlainTextBody(email));
}
else {
if (CkEmailW_HasHtmlBody(email) == TRUE) {
reader = CkHtmlToTextW_Create();
wprintf(L"%s\n",CkHtmlToTextW_toText(reader,CkEmailW_getHtmlBody(email)));
}
else {
wprintf(L"No text or HTML body.\n");
}
}
CkEmailW_Dispose(email);
CkHtmlToTextW_Dispose(reader);
}