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

Render an Email to MIME Bytes in a BinData

See more SMTP Examples

Demonstrates the Chilkat MailMan.RenderToMimeBd method, which renders an Email object as MIME bytes and appends the result to a BinData, without sending the email. This example renders a message into a BinData and prints the byte count.

Background: This is the binary version of RenderToMime. A BinData holds raw bytes, which is the right container when you want the rendered MIME as binary — to write it directly to a file or socket, hash it, or hand it to another API expecting a byte buffer — rather than as text.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkMailManW.h>
#include <CkEmailW.h>
#include <CkBinDataW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Demonstrates the MailMan.RenderToMimeBd method, which renders an Email object as MIME
    //  bytes and appends the result to a BinData (without sending the email).

    CkMailManW mailman;

    //  Build the email to render.
    CkEmailW email;
    email.put_Subject(L"Rendered email");
    email.put_From(L"alice@example.com");
    email.AddTo(L"Bob",L"bob@example.com");
    email.put_Body(L"This message is rendered to MIME bytes in a BinData.");

    //  Render the MIME into a BinData.
    CkBinDataW bdMime;

    success = mailman.RenderToMimeBd(email,bdMime);
    if (success == false) {
        wprintf(L"%s\n",mailman.lastErrorText());
        return;
    }

    wprintf(L"Rendered MIME size (bytes) = %d\n",bdMime.get_NumBytes());
    }