Lazarus Pascal Requires Chilkat v11.0.0+
Lazarus Pascal
Convert image data URLs to related MIME parts
See more Email Object Examples
Start with HTML that contains image bytes in a data URL. Convert it to conventional CID references and inspect the resulting related-item count before saving.
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;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
email: TEmail;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TEmail.Create;
email.From := 'Workshop team <events@example.com>';
success := email.AddTo('Alex Rivera','alex@example.net');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
email.Subject := 'Workshop registration';
email.SetHtmlBody('<html><body><p>Registration confirmed.</p><img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" alt="Mark"></body></html>');
success := email.ConvertInlineImages();
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
WriteLn('Related images: ' + email.NumRelatedItems);
WriteLn(email.GetHtmlBody());
success := email.SaveEml('related-images.eml');
if (success <> True) then
begin
WriteLn(email.LastErrorText);
Exit;
end;
WriteLn('Saved related-images.eml.');
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.