Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get a Header Field from an Alternative Body
See more Email Object Examples
Demonstrates the Chilkat Email.GetAltHeaderField method, which returns the value of a header field within the Nth alternative body's MIME sub-part. The first argument is the zero-based alternative index; the second is the header field name. This example builds a message with plain-text and HTML alternatives and reads the Content-Type of the first alternative.
Background: A
multipart/alternative message is a tree: each alternative body is its own MIME sub-part with its own little header block (Content-Type, Content-Transfer-Encoding, etc.). The top-level Email header methods read the message headers, whereas GetAltHeaderField reaches into a specific alternative's sub-part — useful for inspecting exactly how each representation is typed and encoded.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
email: TEmail;
ct: string;
begin
// Demonstrates the GetAltHeaderField method, which returns the value of a header field
// within the Nth alternative body's MIME sub-part. The 1st argument is the zero-based
// alternative index; the 2nd is the header field name.
email := TEmail.Create;
// Create an email with plain-text and HTML alternatives.
email.SetTextBody('This is the plain-text alternative.','text/plain');
email.AddHtmlAlternativeBody('<html><body>This is the HTML alternative.</body></html>');
// Get the Content-Type header of the first alternative body (index 0).
ct := email.GetAltHeaderField(0,'Content-Type');
WriteLn('Alternative 0 Content-Type: ' + ct);
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.