Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Download POP3 Email to MIME
Download the email from a POP3 mailbox directly into MIME, without parsing into email objects.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.BinData,
Chilkat.Email,
Chilkat.MailMan;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailman: TMailMan;
stUidls: TStringTable;
bdMime: TBinData;
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';
// First, get the complete set of UIDLs for the email in the POP3 mailbox:
stUidls := TStringTable.Create;
success := mailman.FetchUidls(stUidls);
if (success = False) then
begin
WriteLn(mailman.LastErrorText);
Exit;
end;
// Download each email as MIME.
// If desired, the MIME can be loaded into an email object.
bdMime := TBinData.Create;
email := TEmail.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;
email.SetFromMimeBd(bdMime);
WriteLn('From: ' + email.From);
WriteLn('Subject: ' + email.Subject);
i := i + 1;
end;
mailman.Free;
stUidls.Free;
bdMime.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.