Sample code for 30+ languages & platforms
Visual Basic 6.0 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 Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.

Dim email As New ChilkatEmail
success = email.LoadEml("with-attachments.eml")
If (success <> 1) Then
    Debug.Print email.LastErrorText
    Exit Sub
End If

Dim preview As New ChilkatEmail
success = email.MakeCopy(preview)
If (success <> 1) Then
    Debug.Print email.LastErrorText
    Exit Sub
End If

'  Keep related items: the HTML still refers to them.
preview.DropAttachments 
Debug.Print "Files in original: " & email.NumAttachments & "  Files in preview: " & preview.NumAttachments
If (preview.HasHtmlBody() <> 1) Then
    Debug.Print "This message has no HTML preview."
    Exit Sub
End If

Dim html As New ChilkatStringBuilder
success = preview.GetHtmlBodySb(1,html)
If (success <> 1) Then
    Debug.Print preview.LastErrorText
    Exit Sub
End If

success = html.WriteFile("preview.html","utf-8",0)
If (success <> 1) Then
    Debug.Print "Failed: html.WriteFile."
    Exit Sub
End If

Debug.Print "Saved preview.html."