Sample code for 30+ languages & platforms
C

Make a Copy of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.MakeCopy method, which copies the entire state of this email into another Email object — message content, recipients, headers, body representations, attachments, and related items. This example copies an email and reads a couple of fields from the copy.

Background: A deep copy gives you an independent duplicate: changes to one object do not affect the other. This is handy for template-and-tweak workflows — build a base message once, copy it per recipient, then vary only the recipient or a few fields — without risk of one send's edits bleeding into the next.

Chilkat C Downloads

C
#include <C_CkEmail.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmail email;
    HCkEmail copy;

    success = FALSE;

    //  Demonstrates the MakeCopy method, which copies the entire state of this email into
    //  another Email object -- message content, recipients, headers, bodies, attachments, and
    //  related items.

    email = CkEmail_Create();
    CkEmail_putSubject(email,"Original");
    CkEmail_putFrom(email,"alice@example.com");
    CkEmail_AddTo(email,"Bob","bob@example.com");
    CkEmail_putBody(email,"Original body.");

    //  Copy the entire email into a new Email object.
    copy = CkEmail_Create();

    success = CkEmail_MakeCopy(email,copy);
    if (success == FALSE) {
        printf("%s\n",CkEmail_lastErrorText(email));
        CkEmail_Dispose(email);
        CkEmail_Dispose(copy);
        return;
    }

    printf("Copy subject: %s\n",CkEmail_subject(copy));
    printf("Copy NumTo: %d\n",CkEmail_getNumTo(copy));


    CkEmail_Dispose(email);
    CkEmail_Dispose(copy);

    }