Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Authenticate with the POP3 Server

See more POP3 Examples

Demonstrates the Chilkat MailMan.Pop3Authenticate method, which authenticates with the POP3 server using the current POP3 property settings, such as PopUsername and PopPassword. It is typically called after Pop3Connect. This example connects and then authenticates.

Background: POP3 authentication is the step, after connecting, where the client identifies itself — classically with the USER and PASS commands, or a more secure mechanism. Calling Pop3Connect and Pop3Authenticate as distinct steps lets you determine precisely which phase fails, and lets you hold an authenticated session open to perform several mailbox operations before ending it with Pop3EndSession.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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;

begin
  success := False;

  //  Demonstrates the MailMan.Pop3Authenticate method, which authenticates with the POP3 server
  //  using the current POP3 property settings (such as PopUsername and PopPassword).  It is
  //  typically called after Pop3Connect.

  mailman := TMailMan.Create;

  //  Configure the POP3 server connection.
  mailman.MailHost := 'pop.example.com';
  mailman.MailPort := 995;
  mailman.PopSsl := True;
  mailman.PopUsername := 'user@example.com';
  mailman.PopPassword := 'myPassword';

  //  Connect first, then authenticate.

  success := mailman.Pop3Connect();
  if (success = False) then
    begin
      WriteLn(mailman.LastErrorText);
      Exit;
    end;

  success := mailman.Pop3Authenticate();
  if (success = False) then
    begin
      WriteLn(mailman.LastErrorText);
      Exit;
    end;

  WriteLn('Authenticated with the POP3 server.');


  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.