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

Connecting to GMAIL using IMAP

Demonstrates how to connect to GMAIL using IMAP.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkImapW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkImapW imap;

    // Turn on session logging:
    imap.put_KeepSessionLog(true);

    // Connect to GMail
    // Use TLS
    imap.put_Ssl(true);
    imap.put_Port(993);
    success = imap.Connect(L"imap.gmail.com");
    if (success != true) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }

    // Login
    // Your login is typically your GMail email address.
    success = imap.Login(L"username@gmail.com",L"myPassword");
    if (success != true) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }

    // Select an IMAP mailbox
    success = imap.SelectMailbox(L"Inbox");
    if (success != true) {
        wprintf(L"%s\n",imap.lastErrorText());
        return;
    }

    // Show the session log.
    wprintf(L"%s\n",imap.sessionLog());

    // Disconnect from the IMAP server.
    success = imap.Disconnect();
    }