B4X Requires Chilkat v11.0.0+
B4X
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 B4X Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim email As ChilkatEmail
email.Initialize
success = email.LoadEml("with-attachments.eml")
If success <> True Then
Log(email.LastErrorText)
Return
End If
Dim preview As ChilkatEmail
preview.Initialize
success = email.MakeCopy(preview)
If success <> True Then
Log(email.LastErrorText)
Return
End If
' Keep related items: the HTML still refers to them.
preview.DropAttachments
Log("Files in original: " & email.NumAttachments & " Files in preview: " & preview.NumAttachments)
If preview.HasHtmlBody <> True Then
Log("This message has no HTML preview.")
Return
End If
Dim html As ChilkatStringBuilder
html.Initialize
success = preview.GetHtmlBodySb(True, html)
If success <> True Then
Log(preview.LastErrorText)
Return
End If
success = html.WriteFile("preview.html", "utf-8", False)
If success <> True Then
Log("Failed: html.WriteFile.")
Return
End If
Log("Saved preview.html.")