Sample code for 30+ languages & platforms
Unicode C++

Serialize MIME to a StringBuilder

See more MIME Examples

Demonstrates the Chilkat Mime.GetMimeSb method, which serializes the complete MIME entity and appends it to a StringBuilder. The only argument is the StringBuilder; existing content is preserved.

Background: Serializing into a StringBuilder avoids creating a new string and is convenient when you are accumulating output or building a larger document. Because it appends, you can assemble several pieces in one buffer. As with GetMime, use the BinData form for content with arbitrary binary bytes.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkMimeW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Demonstrates the Mime.GetMimeSb method, which serializes the complete MIME entity and appends
    //  it to a StringBuilder.  The only argument is the StringBuilder.

    CkMimeW mime;

    success = mime.SetBodyFromPlainText(L"Hello, this is the message body.");
    if (success == false) {
        wprintf(L"%s\n",mime.lastErrorText());
        return;
    }

    //  Append the serialized MIME to a StringBuilder.  Existing content is preserved.
    CkStringBuilderW sb;
    success = mime.GetMimeSb(sb);
    if (success == false) {
        wprintf(L"%s\n",mime.lastErrorText());
        return;
    }

    wprintf(L"%s\n",sb.getAsString());
    }