Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Fetch the UIDLs of All POP3 Messages
See more POP3 Examples
Demonstrates the Chilkat MailMan.FetchUidls method, which retrieves the UIDLs of the messages currently in the POP3 mailbox and stores them in a StringTable, one entry per message, in the server's current mailbox order. This example lists every UIDL.
Background: The UIDL list is the starting point for incremental mail retrieval. A client keeps a record of the UIDLs it has already downloaded; on each check it fetches the current list, computes the difference, and downloads only the new ones (see
FetchUidlSet). This is how "leave a copy on the server" works without repeatedly re-downloading the same messages.Chilkat Pascal (Lazarus/Delphi) 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,
Chilkat.StringTable;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
uidls: TStringTable;
n: Integer;
i: Integer;
begin
success := False;
// Demonstrates the MailMan.FetchUidls method, which retrieves the UIDLs of the messages
// currently in the POP3 mailbox and stores them in a StringTable, one entry per message, in
// the server's current mailbox order.
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';
// Retrieve the UIDLs of all messages in the mailbox.
uidls := TStringTable.Create;
success := mailman.FetchUidls(uidls);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
n := uidls.Count;
WriteLn('Mailbox contains ' + n + ' messages.');
for i := 0 to n - 1 do
begin
WriteLn('UIDL ' + i + ': ' + uidls.StringAt(i));
end;
// Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
// connects and authenticates -- using the property settings above -- whenever a server
// operation requires it. Calling the explicit connect/authenticate methods can still be
// helpful to determine whether a failure occurs while connecting or while authenticating.
mailman.Free;
uidls.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.