Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Remove a Single Related Item from an Email
See more Email Object Examples
Demonstrates the Chilkat Email.DropRelatedItem method, which removes the related item at a given zero-based index. A related item is typically an embedded image or style sheet referenced from the HTML body (via a cid: link or Content-Location). This example adds a related style sheet, then removes it by index, printing the count before and after.
Background: Related items live in the message's
multipart/related enclosure and are indexed from 0 to NumRelatedItems - 1. Removing one by index is useful when editing a received message — for example stripping a tracking pixel or an unwanted embedded image — while leaving the HTML body and any other related resources in place. To remove them all at once, use DropRelatedItems.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;
begin
// Demonstrates the DropRelatedItem method, which removes the related item at a given
// zero-based index. A related item is typically an embedded image or style sheet
// referenced from the HTML body.
email := TEmail.Create;
// Set an HTML body that references a related style sheet by name (Content-Location).
email.SetHtmlBody('<html><head><link rel="stylesheet" href="styles.css"/></head><body>Styled.</body></html>');
// Add the related item (becomes index 0).
email.AddRelatedString2('styles.css','body { color: navy; }','utf-8');
WriteLn('NumRelatedItems before = ' + email.NumRelatedItems);
// Remove the related item at index 0.
email.DropRelatedItem(0);
WriteLn('NumRelatedItems after = ' + email.NumRelatedItems);
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.