Sample code for 30+ languages & platforms
Unicode C Requires Chilkat v11.0.0+

Create, save, and reopen a plain-text email

See more Email Object Examples

Set the sender, recipient, subject, and plain-text body. Save the result as an EML file, then open it in a second Email object and read its contents.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmailW email;
    HCkEmailW received;

    success = FALSE;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    email = CkEmailW_Create();
    CkEmailW_putFrom(email,L"Sam Lee <sam@example.com>");
    success = CkEmailW_AddTo(email,L"Alex Rivera",L"alex@example.net");
    if (success != TRUE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return;
    }

    CkEmailW_putSubject(email,L"Hello");
    CkEmailW_putBody(email,L"This is a plain-text message.");
    success = CkEmailW_SaveEml(email,L"message.eml");
    if (success != TRUE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return;
    }

    received = CkEmailW_Create();
    success = CkEmailW_LoadEml(received,L"message.eml");
    if (success != TRUE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(received));
        CkEmailW_Dispose(email);
        CkEmailW_Dispose(received);
        return;
    }

    wprintf(L"%s\n",CkEmailW_ck_from(received));
    wprintf(L"%s\n",CkEmailW_subject(received));
    wprintf(L"%s\n",CkEmailW_getPlainTextBody(received));


    CkEmailW_Dispose(email);
    CkEmailW_Dispose(received);

    }