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

Retrieve UIDL's from POP3 Server

Retrieve a list of UIDLs from a POP3 server. UIDLs are unique identifiers, 1 to 70 characters long, composed of characters ranging from 0x21 to 0x7E. These identifiers uniquely distinguish messages within a mailbox and remain consistent across sessions.

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.StringTable,
  Chilkat.Email,
  Chilkat.MailMan;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  mailman: TMailMan;
  stUidls: TStringTable;
  email: TEmail;
  count: Integer;
  i: Integer;
  uidl: string;

begin
  success := False;

  //  This example requires the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  mailman := TMailMan.Create;

  mailman.MailHost := 'pop.example.com';

  mailman.PopUsername := 'myLogin';
  mailman.PopPassword := 'myPassword';

  mailman.MailPort := 995;
  mailman.PopSsl := True;

  stUidls := TStringTable.Create;
  success := mailman.FetchUidls(stUidls);
  if (success = False) then
    begin
      WriteLn(mailman.LastErrorText);
      Exit;
    end;

  //  Download each email by UIDL.
  email := TEmail.Create;

  count := stUidls.Count;
  i := 0;
  while i < count do
    begin
      //  Download the full email.
      uidl := stUidls.StringAt(i);
      success := mailman.FetchByUidl(uidl,False,0,email);
      if (success = False) then
        begin
          WriteLn(mailman.LastErrorText);
          Exit;
        end;

      WriteLn(i);
      WriteLn('UIDL: ' + uidl);
      WriteLn('From: ' + email.From);
      WriteLn('Subject: ' + email.Subject);

      i := i + 1;
    end;

  mailman.Pop3EndSession();


  mailman.Free;
  stUidls.Free;
  email.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.