Sample code for 30+ languages & platforms
Unicode C

Create a multipart/mixed MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.NewMultipartMixed method, which initializes the object as an empty multipart/mixed entity, clearing any existing content. It takes no arguments; child parts are then appended.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: multipart/mixed is the container for independent parts shown one after another — the classic "message body plus attachments" layout. Each child is its own distinct content, unlike multipart/alternative (competing renderings of the same thing) or multipart/related (a part and its embedded resources). Start here, then AppendPart a body and AppendPartFromFile the attachments.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMimeW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMimeW mime;
    HCkMimeW bodyPart;

    success = FALSE;

    //  Demonstrates the Mime.NewMultipartMixed method, which initializes the object as an empty
    //  multipart/mixed entity, clearing any existing headers, body, and child parts.  It takes no
    //  arguments.

    mime = CkMimeW_Create();

    success = CkMimeW_NewMultipartMixed(mime);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        return;
    }

    //  Append child parts.  multipart/mixed is the container for a message body plus attachments.
    bodyPart = CkMimeW_Create();
    success = CkMimeW_SetBodyFromPlainText(bodyPart,L"See the attached report.");
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(bodyPart));
        CkMimeW_Dispose(mime);
        CkMimeW_Dispose(bodyPart);
        return;
    }

    success = CkMimeW_AppendPart(mime,bodyPart);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        CkMimeW_Dispose(bodyPart);
        return;
    }

    success = CkMimeW_AppendPartFromFile(mime,L"qa_data/report.pdf");
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        CkMimeW_Dispose(bodyPart);
        return;
    }

    wprintf(L"Number of parts: %d\n",CkMimeW_getNumParts(mime));


    CkMimeW_Dispose(mime);
    CkMimeW_Dispose(bodyPart);

    }