Sample code for 30+ languages & platforms
Unicode C++

Delete an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.DeleteMailbox method, which deletes a mailbox from the IMAP server. This deletes the mailbox itself, not merely the messages it contains. This example deletes a mailbox named OldFolder.

Background: Deleting a mailbox removes the folder and everything in it — an irreversible action, so applications typically confirm first. Server rules can add constraints: some refuse to delete a folder that still has child folders, or that is currently selected. This is the counterpart to CreateMailbox; to remove individual messages rather than a whole folder, mark them deleted and Expunge.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkImapW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Demonstrates the Imap.DeleteMailbox method, which deletes a mailbox from the IMAP server.
    //  This deletes the mailbox itself, not merely the messages it contains.

    CkImapW imap;

    imap.put_Ssl(true);
    imap.put_Port(993);

    success = imap.Connect(L"imap.example.com");
    if (success == false) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }

    success = imap.Login(L"user@example.com",L"myPassword");
    if (success == false) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }

    //  Delete a mailbox (folder) from the server.
    success = imap.DeleteMailbox(L"OldFolder");
    if (success == false) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }

    wprintf(L"Mailbox deleted.\n");

    success = imap.Disconnect();
    if (success == false) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }
    }