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

POP3 Fetch Mime Source of Email by UIDL

Demonstrates how to fetch the MIME source of a single email by UIDL.

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

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

procedure RunDemo;
var
  success: Boolean;
  mailman: TMailMan;
  stUidls: TStringTable;
  bdMime: TBinData;
  count: Integer;
  i: Integer;

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 as MIME.
  bdMime := TBinData.Create;

  count := stUidls.Count;
  i := 0;
  while i < count do
    begin
      success := mailman.FetchMimeBd(stUidls.StringAt(i),bdMime);
      if (success = False) then
        begin
          WriteLn(mailman.LastErrorText);
          Exit;
        end;

      //  Do whatever is needed with the MIME contained in bdMime.

      i := i + 1;
    end;



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