Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Add a Plain-Text Alternative Body to an Email
See more Email Object Examples
Demonstrates the Chilkat Email.AddPlainTextAlternativeBody method, which adds a plain-text alternative body. Combined with an HTML body, it produces a multipart/alternative email that carries both representations. This example sets an HTML body, adds a plain-text alternative, and prints the alternative count.
Background: This is the companion to
AddHtmlAlternativeBody. A polished email provides both an HTML body (for rich display) and a plain-text fallback, and the receiving client picks whichever it prefers. Including a real plain-text alternative — rather than letting the HTML stand alone — improves accessibility, helps with spam scoring, and guarantees the message is readable in text-only environments.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 AddPlainTextAlternativeBody method, which adds a plain-text alternative
// body. Combined with an HTML body, this produces a multipart/alternative email offering
// both representations of the same content.
email := TEmail.Create;
email.Subject := 'HTML with a plain-text alternative';
// Set an HTML body.
email.SetHtmlBody('<html><body><b>This is the HTML version.</b></body></html>');
// Add a plain-text alternative.
email.AddPlainTextAlternativeBody('This is the plain-text version.');
WriteLn('NumAlternatives = ' + email.NumAlternatives);
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.