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

Delphi DLL
var
success: Boolean;
mailman: HCkMailMan;
count: Integer;

begin
success := False;

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

mailman := CkMailMan_Create();
//  Use a provider that explicitly supports POP STLS on port 110.
//  Gmail documents implicit TLS on pop.gmail.com:995 instead.
CkMailMan_putMailHost(mailman,'pop.example.com');
CkMailMan_putMailPort(mailman,110);
CkMailMan_putPopSsl(mailman,False);
CkMailMan_putPop3Stls(mailman,True);
CkMailMan_putPop3StlsIfPossible(mailman,False);
CkMailMan_putRequireSslCertVerify(mailman,True);
CkMailMan_putPopUsername(mailman,'user@example.com');
CkMailMan_putPopPassword(mailman,'YOUR_PROVIDER_ISSUED_PASSWORD');
success := CkMailMan_Pop3BeginSession(mailman);
if (success <> True) then
  begin
    CkMailMan_Pop3EndSessionNoQuit(mailman);
    Memo1.Lines.Add('POP connection or authentication failed. STLS must succeed before credentials are sent.');
    Exit;
  end;
count := CkMailMan_CheckMail(mailman);
if (count < 0) then
  begin
    CkMailMan_Pop3EndSessionNoQuit(mailman);
    Memo1.Lines.Add('Could not obtain the POP message count.');
    Exit;
  end;
Memo1.Lines.Add('Available POP messages: ' + IntToStr(count));
success := CkMailMan_Pop3EndSession(mailman);
if (success <> True) then
  begin
    Memo1.Lines.Add('The count was obtained, but closing the POP session failed.');
  end;

CkMailMan_Dispose(mailman);