Sample code for 30+ languages & platforms
Unicode C

Delete a Bundle of POP3 Messages

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs stored in the X-UIDL headers of the Email objects in an EmailBundle. An email without an X-UIDL header is skipped. This example fetches all messages and deletes them.

Background: DeleteBundle is the batch version of DeleteEmail: it marks every message in a downloaded bundle for deletion in one call. A typical "download and clear the mailbox" workflow is to fetch all messages, process them, then delete the whole bundle. Because a bundle can be filtered or built selectively, you can also delete just the subset you no longer need. The deletions commit when the POP3 session ends.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMailManW.h>
#include <C_CkEmailBundleW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMailManW mailman;
    HCkEmailBundleW bundle;

    success = FALSE;

    //  Demonstrates the MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs
    //  stored in the X-UIDL headers of the Email objects in an EmailBundle.  An email without an
    //  X-UIDL header is skipped.

    mailman = CkMailManW_Create();

    //  Configure the POP3 server connection.
    CkMailManW_putMailHost(mailman,L"pop.example.com");
    CkMailManW_putMailPort(mailman,995);
    CkMailManW_putPopSsl(mailman,TRUE);
    CkMailManW_putPopUsername(mailman,L"user@example.com");
    CkMailManW_putPopPassword(mailman,L"myPassword");

    //  Fetch all messages (headers are enough; each carries an X-UIDL header).
    bundle = CkEmailBundleW_Create();

    success = CkMailManW_FetchAll(mailman,TRUE,TRUE,0,bundle);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkMailManW_Dispose(mailman);
        CkEmailBundleW_Dispose(bundle);
        return;
    }

    //  Delete every message in the bundle.
    success = CkMailManW_DeleteBundle(mailman,bundle);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkMailManW_Dispose(mailman);
        CkEmailBundleW_Dispose(bundle);
        return;
    }

    //  Unless the ImmediateDelete property is set to TRUE, the messages are only marked for
    //  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletions.
    success = CkMailManW_Pop3EndSession(mailman);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkMailManW_Dispose(mailman);
        CkEmailBundleW_Dispose(bundle);
        return;
    }

    wprintf(L"Deleted %d messages from the POP3 server.\n",CkEmailBundleW_getMessageCount(bundle));

    //  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
    //  connects and authenticates -- using the property settings above -- whenever a server
    //  operation requires it.  Calling the explicit connect/authenticate methods can still be
    //  helpful to determine whether a failure occurs while connecting or while authenticating.


    CkMailManW_Dispose(mailman);
    CkEmailBundleW_Dispose(bundle);

    }