Sample code for 30+ languages & platforms
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 C Downloads

C
#include <C_CkMime.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMime mime;
    HCkMime part;
    const char *mimeStr;

    success = FALSE;

    mime = CkMime_Create();

    //  Create a multipart/mixed entity.
    success = CkMime_NewMultipartMixed(mime);
    if (success == FALSE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        CkMime_Dispose(mime);
        return;
    }

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

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

    //  Add a simple part so the multipart has content.
    part = CkMime_Create();
    success = CkMime_SetBodyFromPlainText(part,"First part.");
    if (success == FALSE) {
        printf("%s\n",CkMime_lastErrorText(part));
        CkMime_Dispose(mime);
        CkMime_Dispose(part);
        return;
    }

    success = CkMime_AppendPart(mime,part);
    if (success == FALSE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        CkMime_Dispose(mime);
        CkMime_Dispose(part);
        return;
    }

    printf("Boundary = %s\n",CkMime_boundary(mime));

    mimeStr = CkMime_getMime(mime);
    if (CkMime_getLastMethodSuccess(mime) == FALSE) {
        printf("%s\n",CkMime_lastErrorText(mime));
        CkMime_Dispose(mime);
        CkMime_Dispose(part);
        return;
    }

    printf("%s\n",mimeStr);


    CkMime_Dispose(mime);
    CkMime_Dispose(part);

    }