Sample code for 30+ languages & platforms
Unicode C

Clear an Email Object

See more Email Object Examples

Demonstrates the Chilkat Email.Clear method, which removes the current message content — recipients, headers, body representations, attachments, related items, and embedded messages — leaving an empty email object. This example builds a message with a recipient and attachment, clears it, and prints the counts before and after.

Background: Reusing a single Email object across many operations is efficient, but leftover state from a previous message could leak into the next. Clear resets the object completely, giving you a clean slate — the safe way to start a fresh message without allocating a new object.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    HCkEmailW email;

    //  Demonstrates the Clear method, which removes the current message content, including
    //  recipients, headers, body representations, attachments, related items, and embedded
    //  messages -- leaving an empty email object.

    email = CkEmailW_Create();
    CkEmailW_putSubject(email,L"A message");
    CkEmailW_putBody(email,L"Some body text.");
    CkEmailW_AddTo(email,L"Bob",L"bob@example.com");
    CkEmailW_AddStringAttachment(email,L"notes.txt",L"Some notes.");

    wprintf(L"NumTo before clear = %d\n",CkEmailW_getNumTo(email));
    wprintf(L"NumAttachments before clear = %d\n",CkEmailW_getNumAttachments(email));

    //  Remove all content, resetting the email object.
    CkEmailW_Clear(email);

    wprintf(L"NumTo after clear = %d\n",CkEmailW_getNumTo(email));
    wprintf(L"NumAttachments after clear = %d\n",CkEmailW_getNumAttachments(email));


    CkEmailW_Dispose(email);

    }