Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get the Content-Type of Each Alternative Body
See more Email Object Examples
Demonstrates the Chilkat Email.GetAlternativeContentType method, which returns the content type of the Nth alternative body. The NumAlternatives property gives the number of alternatives, and indexes are zero-based. This example builds a message with plain-text and HTML alternatives and prints the content type of each.
Background: Each alternative in a
multipart/alternative message declares a Content-Type such as text/plain or text/html. Enumerating those types tells you which representations a message actually contains before you fetch a body — letting you decide, for instance, whether an HTML version exists or whether you must fall back to plain text. It is the natural companion to GetAlternativeBody, which fetches the body at the same index.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;
n: Integer;
i: Integer;
begin
// Demonstrates the GetAlternativeContentType method, which returns the content type of
// the Nth alternative body. The NumAlternatives property gives the number of
// alternatives; indexes are zero-based.
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>');
n := email.NumAlternatives;
for i := 0 to n - 1 do
begin
WriteLn('Alternative ' + i + ' content type: ' + email.GetAlternativeContentType(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.