Sample code for 30+ languages & platforms
DataFlex 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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    Integer iCount

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End
    //  Use a provider that explicitly supports POP STLS on port 110.
    //  Gmail documents implicit TLS on pop.gmail.com:995 instead.
    Set ComMailHost Of hoMailman To "pop.example.com"
    Set ComMailPort Of hoMailman To 110
    Set ComPopSsl Of hoMailman To False
    Set ComPop3Stls Of hoMailman To True
    Set ComPop3StlsIfPossible Of hoMailman To False
    Set ComRequireSslCertVerify Of hoMailman To True
    Set ComPopUsername Of hoMailman To "user@example.com"
    Set ComPopPassword Of hoMailman To "YOUR_PROVIDER_ISSUED_PASSWORD"
    Get ComPop3BeginSession Of hoMailman To iSuccess
    If (iSuccess <> True) Begin
        Get ComPop3EndSessionNoQuit Of hoMailman To iSuccess
        Showln "POP connection or authentication failed. STLS must succeed before credentials are sent."
        Procedure_Return
    End

    Get ComCheckMail Of hoMailman To iCount
    If (iCount < 0) Begin
        Get ComPop3EndSessionNoQuit Of hoMailman To iSuccess
        Showln "Could not obtain the POP message count."
        Procedure_Return
    End

    Showln "Available POP messages: " iCount
    Get ComPop3EndSession Of hoMailman To iSuccess
    If (iSuccess <> True) Begin
        Showln "The count was obtained, but closing the POP session failed."
    End



End_Procedure