Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Iterate Email Headers
Demonstrates how to iterate over the email header fields.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.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
n: Integer;
i: Integer;
name: string;
value: string;
begin
success := False;
email := TEmail.Create;
// First, load an email from a file.
// Note: an email object may be loaded from a file, or
// downloaded directly from a POP3 or IMAP server...
success := email.LoadEml('testReceivedHdrs.eml');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
// How many header fields?
n := email.NumHeaderFields;
if (n > 0) then
begin
// Display the name and value of each header:
for i := 0 to n - 1 do
begin
name := email.GetHeaderFieldName(i);
value := email.GetHeaderFieldValue(i);
WriteLn(i);
WriteLn(name);
WriteLn(value);
end;
end;
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.