Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Set a MIME Body from HTML
See more MIME Examples
Demonstrates the Chilkat Mime.SetBodyFromHtml method, which sets the body as HTML and changes the media type to text/html. The only argument is the HTML text.
Background: Setting an HTML body is how you produce the rich-formatted part of a message. Chilkat marks it
text/html and chooses the encoding based on the content — 7bit for ASCII, a charset-aware encoding otherwise. In practice an HTML email is usually paired with a plain-text alternative inside a multipart/alternative so clients that cannot render HTML still have readable text.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.Mime;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mime: TMime;
html: string;
begin
success := False;
// Demonstrates the Mime.SetBodyFromHtml method, which sets the body as HTML and changes the media
// type to text/html. The only argument is the HTML text.
mime := TMime.Create;
html := '<html><body><h1>Hello</h1><p>This is an HTML body.</p></body></html>';
success := mime.SetBodyFromHtml(html);
if (success = False) then
begin
WriteLn(mime.LastErrorText);
Exit;
end;
WriteLn('Content-Type: ' + mime.ContentType);
mime.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.