Sample code for 30+ languages & platforms
Visual FoxPro Requires Chilkat v11.0.0+

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loEmail
LOCAL loPreview
LOCAL loHtml

lnSuccess = 0

*  Assumes Chilkat is unlocked. See Global Unlock Sample.

loEmail = CreateObject('Chilkat.Email')
lnSuccess = loEmail.LoadEml("with-attachments.eml")
IF (lnSuccess <> 1) THEN
    ? loEmail.LastErrorText
    RELEASE loEmail
    CANCEL
ENDIF

loPreview = CreateObject('Chilkat.Email')
lnSuccess = loEmail.MakeCopy(loPreview)
IF (lnSuccess <> 1) THEN
    ? loEmail.LastErrorText
    RELEASE loEmail
    RELEASE loPreview
    CANCEL
ENDIF

*  Keep related items: the HTML still refers to them.
loPreview.DropAttachments()
? "Files in original: " + STR(loEmail.NumAttachments) + "  Files in preview: " + STR(loPreview.NumAttachments)
IF (loPreview.HasHtmlBody() <> 1) THEN
    ? "This message has no HTML preview."
    RELEASE loEmail
    RELEASE loPreview
    CANCEL
ENDIF

loHtml = CreateObject('Chilkat.StringBuilder')
lnSuccess = loPreview.GetHtmlBodySb(1,loHtml)
IF (lnSuccess <> 1) THEN
    ? loPreview.LastErrorText
    RELEASE loEmail
    RELEASE loPreview
    RELEASE loHtml
    CANCEL
ENDIF

lnSuccess = loHtml.WriteFile("preview.html","utf-8",0)
IF (lnSuccess <> 1) THEN
    ? "Failed: html.WriteFile."
    RELEASE loEmail
    RELEASE loPreview
    RELEASE loHtml
    CANCEL
ENDIF

? "Saved preview.html."

RELEASE loEmail
RELEASE loPreview
RELEASE loHtml