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 <CkEmailW.h>
#include <CkHtmlToTextW.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;
}
wprintf(L"From: %s\n",email.ck_from());
wprintf(L"Subject: %s\n",email.subject());
wprintf(L"Date: %s\n",email.emailDateStr());
int i = 0;
while ((i < email.get_NumTo())) {
wprintf(L"To: %s %s\n",email.getToName(i),email.getToAddr(i));
i = i + 1;
}
const wchar_t *referenceId = email.getHeaderField(L"X-Reference-ID");
if (email.get_LastMethodSuccess() == true) {
wprintf(L"Reference: %s\n",referenceId);
}
if (email.HasPlainTextBody() == true) {
wprintf(L"%s\n",email.getPlainTextBody());
}
else {
if (email.HasHtmlBody() == true) {
CkHtmlToTextW reader;
wprintf(L"%s\n",reader.toText(email.getHtmlBody()));
}
else {
wprintf(L"No text or HTML body.\n");
}
}
}