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.
Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.MailMan;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
count: Integer;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
mailman := TMailMan.Create;
// Use a provider that explicitly supports POP STLS on port 110.
// Gmail documents implicit TLS on pop.gmail.com:995 instead.
mailman.MailHost := 'pop.example.com';
mailman.MailPort := 110;
mailman.PopSsl := False;
mailman.Pop3Stls := True;
mailman.Pop3StlsIfPossible := False;
mailman.RequireSslCertVerify := True;
mailman.PopUsername := 'user@example.com';
mailman.PopPassword := 'YOUR_PROVIDER_ISSUED_PASSWORD';
success := mailman.Pop3BeginSession();
if (success <> True) then
begin
mailman.Pop3EndSessionNoQuit();
WriteLn('POP connection or authentication failed. STLS must succeed before credentials are sent.');
Exit;
end;
count := mailman.CheckMail();
if (count < 0) then
begin
mailman.Pop3EndSessionNoQuit();
WriteLn('Could not obtain the POP message count.');
Exit;
end;
WriteLn('Available POP messages: ' + count);
success := mailman.Pop3EndSession();
if (success <> True) then
begin
WriteLn('The count was obtained, but closing the POP session failed.');
end;
mailman.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.