Sample code for 30+ languages & platforms
Tcl

Render an Email to MIME in a StringBuilder

See more SMTP Examples

Demonstrates the Chilkat MailMan.RenderToMimeSb method, which renders an Email object as MIME text and appends the result to a StringBuilder, without sending the email. This example renders a message into a StringBuilder and prints it.

Background: This is the StringBuilder version of RenderToMime. Appending into a StringBuilder is more efficient when the MIME is large or when you plan to further inspect or manipulate it — searching, replacing, or accumulating additional text — without creating extra intermediate string copies.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the MailMan.RenderToMimeSb method, which renders an Email object as MIME text
#  and appends the result to a StringBuilder (without sending the email).

set mailman [new_CkMailMan]

#  Build the email to render.
set email [new_CkEmail]

CkEmail_put_Subject $email "Rendered email"
CkEmail_put_From $email "alice@example.com"
CkEmail_AddTo $email "Bob" "bob@example.com"
CkEmail_put_Body $email "This message is rendered to MIME in a StringBuilder."

#  Render the MIME into a StringBuilder.
set sbMime [new_CkStringBuilder]

set success [CkMailMan_RenderToMimeSb $mailman $email $sbMime]
if {$success == 0} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    delete_CkEmail $email
    delete_CkStringBuilder $sbMime
    exit
}

puts [CkStringBuilder_getAsString $sbMime]

delete_CkMailMan $mailman
delete_CkEmail $email
delete_CkStringBuilder $sbMime