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

Get the Value of the Nth Header Field

See more Email Object Examples

Demonstrates the Chilkat Email.GetHeaderFieldValue method, which returns the value of the Nth header field. Indexing begins at 0, and the count comes from NumHeaderFields. This example walks every header field, printing each name together with its value.

Background: GetHeaderFieldValue is the value half of index-based header enumeration — GetHeaderFieldName gives the field name at the same index. Iterating both is the reliable way to dump or inspect a full header block, including any repeated fields, which a name-based lookup would collapse to a single occurrence.

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.Email;

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

procedure RunDemo;
var
  email: TEmail;
  n: Integer;
  i: Integer;

begin
  //  Demonstrates the GetHeaderFieldValue method, which returns the value of the Nth header
  //  field.  Indexing begins at 0; the number of header fields is given by NumHeaderFields.

  email := TEmail.Create;
  email.Subject := 'Enumerate header values';
  email.From := 'alice@example.com';
  email.AddTo('Bob','bob@example.com');

  n := email.NumHeaderFields;

  for i := 0 to n - 1 do
    begin
      WriteLn(email.GetHeaderFieldName(i) + ' = ' + email.GetHeaderFieldValue(i));
    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.