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

Forward an email as an attachment

See more Email Object Examples

Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkEmailW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkEmailW original;
    success = original.LoadEml(L"message.eml");
    if (success != true) {
        wprintf(L"%s\n",original.lastErrorText());
        return;
    }

    CkEmailW email;
    email.put_From(L"Sam Lee <sam@example.com>");
    success = email.AddTo(L"Alex Rivera",L"alex@example.net");
    if (success != true) {
        wprintf(L"%s\n",email.lastErrorText());
        return;
    }

    email.put_Subject(L"Forwarded message");
    email.put_Body(L"The original email is attached.");
    success = email.AttachEmail(original);
    if (success != true) {
        wprintf(L"%s\n",email.lastErrorText());
        return;
    }

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

    wprintf(L"Saved forward-as-attachment.eml.\n");
    }