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

Create an email with plain-text and HTML bodies

See more Email Object Examples

Set the From and Reply-To addresses, add a recipient, and provide plain-text and HTML versions of the same body. Save the message as text-and-html.eml.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

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

    success = FALSE;

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

    email = CkEmailW_Create();
    CkEmailW_putFromName(email,L"Sam Lee");
    CkEmailW_putFromAddress(email,L"sam@example.com");
    CkEmailW_putReplyTo(email,L"replies@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"Sample message");
    CkEmailW_putCharset(email,L"utf-8");
    //  A custom header can carry a reference alongside the standard message fields.
    CkEmailW_AddHeaderField(email,L"X-Reference-ID",L"REF-42");
    success = CkEmailW_AddPlainTextAlternativeBody(email,L"Read more at https://example.com/details.");
    if (success != TRUE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return;
    }

    success = CkEmailW_AddHtmlAlternativeBody(email,L"<p><a href='https://example.com/details'>Read more</a></p>");
    if (success != TRUE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return;
    }

    success = CkEmailW_SaveEml(email,L"text-and-html.eml");
    if (success != TRUE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return;
    }

    wprintf(L"Saved text-and-html.eml.\n");


    CkEmailW_Dispose(email);

    }