Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Get the Content-Type of a Related Item
See more Email Object Examples
Demonstrates the Chilkat Email.GetRelatedContentType method, which returns the Content-Type of the Nth related content item in an email. The index is zero-based. This example adds a related style sheet and reads its content type.
Background: Each related item declares a
Content-Type — image/png for an inline image, text/css for a style sheet, and so on — that tells the rendering client how to use it. Reading the content type lets a program enumerate a message's embedded resources and act on them by kind, for example collecting every inline image while ignoring the style sheets.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 GetRelatedContentType method, which returns the Content-Type of the Nth
// related content item in an email. The index is zero-based.
email := TEmail.Create;
email.Subject := 'GetRelatedContentType example';
// The HTML references the style sheet by name (Content-Location).
email.SetHtmlBody('<html><head><link rel="stylesheet" href="styles.css"/></head><body>Styled.</body></html>');
// Add the related style sheet (index 0).
email.AddRelatedString2('styles.css','body { color: navy; }','utf-8');
// Read the Content-Type of the first related item (index 0).
ct := email.GetRelatedContentType(0);
WriteLn('Related item 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.