Delphi ActiveX Requires Chilkat v11.0.0+
Delphi ActiveX
Create an HTML preview with embedded images
See more Email Object Examples
Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
email: TChilkatEmail;
preview: TChilkatEmail;
html: TChilkatStringBuilder;
begin
success := 0;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
email := TChilkatEmail.Create(Self);
success := email.LoadEml('with-attachments.eml');
if (success <> 1) then
begin
Memo1.Lines.Add(email.LastErrorText);
Exit;
end;
preview := TChilkatEmail.Create(Self);
success := email.MakeCopy(preview.ControlInterface);
if (success <> 1) then
begin
Memo1.Lines.Add(email.LastErrorText);
Exit;
end;
// Keep related items: the HTML still refers to them.
preview.DropAttachments();
Memo1.Lines.Add('Files in original: ' + IntToStr(email.NumAttachments) + ' Files in preview: ' + IntToStr(preview.NumAttachments));
if (preview.HasHtmlBody() <> 1) then
begin
Memo1.Lines.Add('This message has no HTML preview.');
Exit;
end;
html := TChilkatStringBuilder.Create(Self);
success := preview.GetHtmlBodySb(1,html.ControlInterface);
if (success <> 1) then
begin
Memo1.Lines.Add(preview.LastErrorText);
Exit;
end;
success := html.WriteFile('preview.html','utf-8',0);
if (success <> 1) then
begin
Memo1.Lines.Add('Failed: html.WriteFile.');
Exit;
end;
Memo1.Lines.Add('Saved preview.html.');