Sample code for 30+ languages & platforms
Unicode C

MIME Multipart Boundary and Preamble Properties

See more MIME Examples

Demonstrates the Boundary property, which gets or sets the raw boundary token of a multipart entity (without surrounding quotation marks), and UseMmDescription, which controls whether the conventional preamble text is emitted when serializing a multipart entity.

Background. A multipart boundary separates the constituent parts. Chilkat quotes the token automatically in the header when required. The preamble is ignored by MIME-aware readers and is off by default.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMimeW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMimeW mime;
    HCkMimeW part;
    const wchar_t *mimeStr;

    success = FALSE;

    mime = CkMimeW_Create();

    //  Create a multipart/mixed entity.
    success = CkMimeW_NewMultipartMixed(mime);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        return;
    }

    //  Boundary is the raw boundary token, without surrounding quotation marks.  Chilkat quotes it
    //  automatically in the serialized header when required.
    CkMimeW_putBoundary(mime,L"example-boundary");

    //  UseMmDescription controls whether the conventional preamble text
    //  "This is a multi-part message in MIME format." is emitted.  The default is FALSE.
    CkMimeW_putUseMmDescription(mime,TRUE);

    //  Add a simple part so the multipart has content.
    part = CkMimeW_Create();
    success = CkMimeW_SetBodyFromPlainText(part,L"First part.");
    if (success == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(part));
        CkMimeW_Dispose(mime);
        CkMimeW_Dispose(part);
        return;
    }

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

    wprintf(L"Boundary = %s\n",CkMimeW_boundary(mime));

    mimeStr = CkMimeW_getMime(mime);
    if (CkMimeW_getLastMethodSuccess(mime) == FALSE) {
        wprintf(L"%s\n",CkMimeW_lastErrorText(mime));
        CkMimeW_Dispose(mime);
        CkMimeW_Dispose(part);
        return;
    }

    wprintf(L"%s\n",mimeStr);


    CkMimeW_Dispose(mime);
    CkMimeW_Dispose(part);

    }