Sample code for 30+ languages & platforms
Unicode C

Remove All Attachments from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.DropAttachments method, which removes all ordinary attachments from the in-memory message. Related items (inline images, style sheets) and attached message/rfc822 emails are not affected. This example adds two attachments, drops them, and prints the count before and after.

Background: Chilkat distinguishes three kinds of enclosed content: ordinary attachments (files meant to be saved), related items (resources that support the HTML display), and nested attached messages. DropAttachments targets only the first category — useful, for example, when forwarding or re-sending a message body without carrying its original file attachments along.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>

void ChilkatSample(void)
    {
    HCkEmailW email;

    //  Demonstrates the DropAttachments method, which removes all ordinary attachments from
    //  the email.  Related items and attached messages are not affected.

    email = CkEmailW_Create();
    CkEmailW_putSubject(email,L"Drop attachments example");

    CkEmailW_AddStringAttachment(email,L"a.txt",L"first attachment");
    CkEmailW_AddStringAttachment(email,L"b.txt",L"second attachment");
    wprintf(L"NumAttachments before = %d\n",CkEmailW_getNumAttachments(email));

    //  Remove all attachments.
    CkEmailW_DropAttachments(email);

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


    CkEmailW_Dispose(email);

    }