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

Tcl

load ./chilkat.dll

set success 0

#  Assumes Chilkat is unlocked. See Global Unlock Sample.

set email [new_CkEmail]

set success [CkEmail_LoadEml $email "with-attachments.eml"]
if {$success != 1} then {
    puts [CkEmail_lastErrorText $email]
    delete_CkEmail $email
    exit
}

set preview [new_CkEmail]

set success [CkEmail_MakeCopy $email $preview]
if {$success != 1} then {
    puts [CkEmail_lastErrorText $email]
    delete_CkEmail $email
    delete_CkEmail $preview
    exit
}

#  Keep related items: the HTML still refers to them.
CkEmail_DropAttachments $preview
puts "Files in original: [CkEmail_get_NumAttachments $email]  Files in preview: [CkEmail_get_NumAttachments $preview]"
if {[CkEmail_HasHtmlBody $preview] != 1} then {
    puts "This message has no HTML preview."
    delete_CkEmail $email
    delete_CkEmail $preview
    exit
}

set html [new_CkStringBuilder]

set success [CkEmail_GetHtmlBodySb $preview 1 $html]
if {$success != 1} then {
    puts [CkEmail_lastErrorText $preview]
    delete_CkEmail $email
    delete_CkEmail $preview
    delete_CkStringBuilder $html
    exit
}

set success [CkStringBuilder_WriteFile $html "preview.html" "utf-8" 0]
if {$success != 1} then {
    puts "Failed: html.WriteFile."
    delete_CkEmail $email
    delete_CkEmail $preview
    delete_CkStringBuilder $html
    exit
}

puts "Saved preview.html."

delete_CkEmail $email
delete_CkEmail $preview
delete_CkStringBuilder $html