Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Download POP3 Email using UIDLs
Demonstrates how to download POP3 email by first getting the complete set of UIDLs and then downloading email by calling FetchByUIDL for each UIDL.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.StringTable,
Chilkat.Email,
Chilkat.MailMan;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
stUidls: TStringTable;
email: TEmail;
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.
// The mailman object is used for receiving (POP3)
// and sending (SMTP) email.
mailman := TMailMan.Create;
// Set the POP3 server's hostname
mailman.MailHost := 'pop.example.com';
// Set the POP3 login/password.
mailman.PopUsername := 'myLogin';
mailman.PopPassword := 'myPassword';
stUidls := TStringTable.Create;
success := mailman.FetchUidls(stUidls);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
email := TEmail.Create;
count := stUidls.Count;
i := 0;
while i < count do
begin
// Download the full email.
success := mailman.FetchByUidl(stUidls.StringAt(i),False,0,email);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
WriteLn(i);
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.