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

Subscribe to an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.Subscribe method, which subscribes the authenticated IMAP account to a mailbox. Subscription controls which mailboxes are returned by subscribed-mailbox listings. This example subscribes to a mailbox.

Background: An account can have many mailboxes, but a user often cares about only some of them. IMAP's subscription list is that curated set: mail clients typically show subscribed folders by default and hide the rest. Subscribing does not create or change a mailbox — it only adds it to the "show me this one" list (retrieved with a subscribed-only listing). Unsubscribe removes it from that list.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkImapW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  Demonstrates the Imap.Subscribe method, which subscribes the authenticated IMAP account to
    //  a mailbox.  Subscription controls which mailboxes are returned by subscribed-mailbox
    //  listings.

    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;
    }

    //  Subscribe to a mailbox.
    success = imap.Subscribe(L"Archive2026");
    if (success == false) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }

    wprintf(L"Subscribed to the mailbox.\n");

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