Sample code for 30+ languages & platforms
Tcl

Render an Email to MIME Bytes in a BinData

See more SMTP Examples

Demonstrates the Chilkat MailMan.RenderToMimeBd method, which renders an Email object as MIME bytes and appends the result to a BinData, without sending the email. This example renders a message into a BinData and prints the byte count.

Background: This is the binary version of RenderToMime. A BinData holds raw bytes, which is the right container when you want the rendered MIME as binary — to write it directly to a file or socket, hash it, or hand it to another API expecting a byte buffer — rather than as text.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the MailMan.RenderToMimeBd method, which renders an Email object as MIME
#  bytes and appends the result to a BinData (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 bytes in a BinData."

#  Render the MIME into a BinData.
set bdMime [new_CkBinData]

set success [CkMailMan_RenderToMimeBd $mailman $email $bdMime]
if {$success == 0} then {
    puts [CkMailMan_lastErrorText $mailman]
    delete_CkMailMan $mailman
    delete_CkEmail $email
    delete_CkBinData $bdMime
    exit
}

puts "Rendered MIME size (bytes) = [CkBinData_get_NumBytes $bdMime]"

delete_CkMailMan $mailman
delete_CkEmail $email
delete_CkBinData $bdMime