Sample code for 30+ languages & platforms
Unicode C Requires Chilkat v11.0.0+

POP3: Require an STLS Upgrade Before Authentication

Connect to a provider that supports POP STLS on port 110, require the TLS upgrade, then authenticate and obtain a message count. Set PopSsl=false, Pop3Stls=true, and enable certificate verification. Replace the generic host and credentials with settings issued by that provider. Use the provider's OAuth or app-password policy where applicable.

The former example was mislabeled: it connected to Gmail on port 995 using implicit TLS and never performed STLS. Gmail's documented POP configuration remains pop.gmail.com:995 with PopSsl=true; use Gmail POP OAuth2 for that connection.

The required STLS setting fails if the upgrade is unavailable. An opportunistic setting can leave a connection unencrypted and is not used here.

See the Gmail SMTP, IMAP, and POP3 guide for current authentication choices and Gmail-specific examples.

Reference documentation

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMailManW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMailManW mailman;
    int count;

    success = FALSE;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    mailman = CkMailManW_Create();
    //  Use a provider that explicitly supports POP STLS on port 110.
    //  Gmail documents implicit TLS on pop.gmail.com:995 instead.
    CkMailManW_putMailHost(mailman,L"pop.example.com");
    CkMailManW_putMailPort(mailman,110);
    CkMailManW_putPopSsl(mailman,FALSE);
    CkMailManW_putPop3Stls(mailman,TRUE);
    CkMailManW_putPop3StlsIfPossible(mailman,FALSE);
    CkMailManW_putRequireSslCertVerify(mailman,TRUE);
    CkMailManW_putPopUsername(mailman,L"user@example.com");
    CkMailManW_putPopPassword(mailman,L"YOUR_PROVIDER_ISSUED_PASSWORD");
    success = CkMailManW_Pop3BeginSession(mailman);
    if (success != TRUE) {
        CkMailManW_Pop3EndSessionNoQuit(mailman);
        wprintf(L"POP connection or authentication failed. STLS must succeed before credentials are sent.\n");
        CkMailManW_Dispose(mailman);
        return;
    }

    count = CkMailManW_CheckMail(mailman);
    if (count < 0) {
        CkMailManW_Pop3EndSessionNoQuit(mailman);
        wprintf(L"Could not obtain the POP message count.\n");
        CkMailManW_Dispose(mailman);
        return;
    }

    wprintf(L"Available POP messages: %d\n",count);
    success = CkMailManW_Pop3EndSession(mailman);
    if (success != TRUE) {
        wprintf(L"The count was obtained, but closing the POP session failed.\n");
    }



    CkMailManW_Dispose(mailman);

    }