Sample code for 30+ languages & platforms
Tcl

Make a Copy of an Email

See more Email Object Examples

Demonstrates the Chilkat Email.MakeCopy method, which copies the entire state of this email into another Email object — message content, recipients, headers, body representations, attachments, and related items. This example copies an email and reads a couple of fields from the copy.

Background: A deep copy gives you an independent duplicate: changes to one object do not affect the other. This is handy for template-and-tweak workflows — build a base message once, copy it per recipient, then vary only the recipient or a few fields — without risk of one send's edits bleeding into the next.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the MakeCopy method, which copies the entire state of this email into
#  another Email object -- message content, recipients, headers, bodies, attachments, and
#  related items.

set email [new_CkEmail]

CkEmail_put_Subject $email "Original"
CkEmail_put_From $email "alice@example.com"
CkEmail_AddTo $email "Bob" "bob@example.com"
CkEmail_put_Body $email "Original body."

#  Copy the entire email into a new Email object.
set copy [new_CkEmail]

set success [CkEmail_MakeCopy $email $copy]
if {$success == 0} then {
    puts [CkEmail_lastErrorText $email]
    delete_CkEmail $email
    delete_CkEmail $copy
    exit
}

puts "Copy subject: [CkEmail_subject $copy]"
puts "Copy NumTo: [CkEmail_get_NumTo $copy]"

delete_CkEmail $email
delete_CkEmail $copy