Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Export HTML with related images embedded as data URLs
See more Email Object Examples
Read inline-image.eml and produce a single UTF-8 HTML file with its related images embedded. This is useful for a self-contained preview. Treat HTML from received mail as untrusted when displaying it.
Chilkat Lazarus Pascal 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,
Chilkat.StringBuilder;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
html: TStringBuilder;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TEmail.Create;
success := email.LoadEml('inline-image.eml');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
if (email.HasHtmlBody() <> True) then
begin
WriteLn('This message has no HTML body.');
Exit;
end;
html := TStringBuilder.Create;
success := email.GetHtmlBodySb(True,html);
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
success := html.WriteFile('preview.html','utf-8',False);
if (success <> True) then
begin
WriteLn('Failed: html.WriteFile.');
Exit;
end;
WriteLn('Saved preview.html.');
email.Free;
html.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.