Sample code for 30+ languages & platforms
Tcl

Clear an Email Object

See more Email Object Examples

Demonstrates the Chilkat Email.Clear method, which removes the current message content — recipients, headers, body representations, attachments, related items, and embedded messages — leaving an empty email object. This example builds a message with a recipient and attachment, clears it, and prints the counts before and after.

Background: Reusing a single Email object across many operations is efficient, but leftover state from a previous message could leak into the next. Clear resets the object completely, giving you a clean slate — the safe way to start a fresh message without allocating a new object.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

#  Demonstrates the Clear method, which removes the current message content, including
#  recipients, headers, body representations, attachments, related items, and embedded
#  messages -- leaving an empty email object.

set email [new_CkEmail]

CkEmail_put_Subject $email "A message"
CkEmail_put_Body $email "Some body text."
CkEmail_AddTo $email "Bob" "bob@example.com"
CkEmail_AddStringAttachment $email "notes.txt" "Some notes."

puts "NumTo before clear = [CkEmail_get_NumTo $email]"
puts "NumAttachments before clear = [CkEmail_get_NumAttachments $email]"

#  Remove all content, resetting the email object.
CkEmail_Clear $email

puts "NumTo after clear = [CkEmail_get_NumTo $email]"
puts "NumAttachments after clear = [CkEmail_get_NumAttachments $email]"

delete_CkEmail $email