Tcl Requires Chilkat v11.0.0+
Tcl
Add an attachment and an inline image
See more Email Object Examples
Add a file attachment from memory and embed an image in the HTML body using its Content-ID. Start with any email that has an HTML body, or use text-and-html.eml from the preceding example. Save the result as with-attachments.eml.
Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Assumes Chilkat is unlocked. See Global Unlock Sample.
set email [new_CkEmail]
set success [CkEmail_LoadEml $email "text-and-html.eml"]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
exit
}
set data [new_CkBinData]
set success [CkBinData_AppendString $data "Time,Activity\r\n09:00,Welcome\r\n10:00,Field session\r\n" "utf-8"]
if {$success != 1} then {
puts "Failed: data.AppendString."
delete_CkEmail $email
delete_CkBinData $data
exit
}
set success [CkEmail_AddAttachmentBd $email "agenda.csv" $data "text/csv"]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
delete_CkBinData $data
exit
}
# AddRelatedBd returns the identifier that must appear after cid: in the HTML.
set image [new_CkBinData]
set success [CkBinData_AppendEncoded $image "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAASUlEQVR4nGMQK/ImBv3//x/CYCBSNQkaIKqJ1YCmGkUDsigu1egakOWwqsaiAaICl2p0P8DV4VKNxdP4VWMPJTyqiY04sZGuAQBhyhp6A/ap2AAAAABJRU5ErkJggg==" "base64"]
if {$success != 1} then {
puts "Failed: image.AppendEncoded."
delete_CkEmail $email
delete_CkBinData $data
delete_CkBinData $image
exit
}
set cid [CkEmail_addRelatedBd $email "confirmed.png" $image]
if {[CkEmail_get_LastMethodSuccess $email] != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
delete_CkBinData $data
delete_CkBinData $image
exit
}
set html [new_CkStringBuilder]
CkStringBuilder_Append $html "<p><img alt='Confirmed' src=\"cid:"
CkStringBuilder_Append $html $cid
CkStringBuilder_Append $html "\"></p>"
CkStringBuilder_Append $html [CkEmail_getHtmlBody $email]
set success [CkEmail_AddHtmlAlternativeBody $email [CkStringBuilder_getAsString $html]]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
delete_CkBinData $data
delete_CkBinData $image
delete_CkStringBuilder $html
exit
}
set success [CkEmail_SaveEml $email "with-attachments.eml"]
if {$success != 1} then {
puts [CkEmail_lastErrorText $email]
delete_CkEmail $email
delete_CkBinData $data
delete_CkBinData $image
delete_CkStringBuilder $html
exit
}
puts "Saved with-attachments.eml."
delete_CkEmail $email
delete_CkBinData $data
delete_CkBinData $image
delete_CkStringBuilder $html