DataFlex Requires Chilkat v11.0.0+
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoEmail
Variant vPreview
Handle hoPreview
Variant vHtml
Handle hoHtml
String sTemp1
Integer iTemp1
Integer iTemp2
Boolean bTemp1
Move False To iSuccess
// Assumes Chilkat is unlocked. See Global Unlock Sample.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Get ComLoadEml Of hoEmail "with-attachments.eml" To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatEmail)) To hoPreview
If (Not(IsComObjectCreated(hoPreview))) Begin
Send CreateComObject of hoPreview
End
Get pvComObject of hoPreview to vPreview
Get ComMakeCopy Of hoEmail vPreview To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
// Keep related items: the HTML still refers to them.
Send ComDropAttachments To hoPreview
Get ComNumAttachments Of hoEmail To iTemp1
Get ComNumAttachments Of hoPreview To iTemp2
Showln "Files in original: " iTemp1 " Files in preview: " iTemp2
Get ComHasHtmlBody Of hoPreview To bTemp1
If (bTemp1 <> True) Begin
Showln "This message has no HTML preview."
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoHtml
If (Not(IsComObjectCreated(hoHtml))) Begin
Send CreateComObject of hoHtml
End
Get pvComObject of hoHtml to vHtml
Get ComGetHtmlBodySb Of hoPreview True vHtml To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoPreview To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComWriteFile Of hoHtml "preview.html" "utf-8" False To iSuccess
If (iSuccess <> True) Begin
Showln "Failed: html.WriteFile."
Procedure_Return
End
Showln "Saved preview.html."
End_Procedure