Sample code for 30+ languages & platforms
Unicode C++ Requires Chilkat v11.0.0+

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkEmailW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmailW wrapper;
    success = wrapper.LoadEml(L"forward-as-attachment.eml");
    if (success != true) {
        wprintf(L"%s\n",wrapper.lastErrorText());
        return;
    }

    wprintf(L"Cover note: %s\n",wrapper.subject());
    if (wrapper.get_NumAttachedMessages() == 0) {
        wprintf(L"No attached messages.\n");
        return;
    }

    CkEmailW nested;
    int i = 0;
    while ((i < wrapper.get_NumAttachedMessages())) {
        success = wrapper.GetAttachedEmail(i,nested);
        if (success != true) {
            wprintf(L"%s\n",wrapper.lastErrorText());
            return;
        }

        wprintf(L"Original author: %s\n",nested.ck_from());
        wprintf(L"Original subject: %s\n",nested.subject());
        wprintf(L"Files on the original: %d\n",nested.get_NumAttachments());
        i = i + 1;
    }
    }