Sample code for 30+ languages & platforms
Tcl

Create a multipart/mixed MIME Entity

See more MIME Examples

Demonstrates the Chilkat Mime.NewMultipartMixed method, which initializes the object as an empty multipart/mixed entity, clearing any existing content. It takes no arguments; child parts are then appended.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: multipart/mixed is the container for independent parts shown one after another — the classic "message body plus attachments" layout. Each child is its own distinct content, unlike multipart/alternative (competing renderings of the same thing) or multipart/related (a part and its embedded resources). Start here, then AppendPart a body and AppendPartFromFile the attachments.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the Mime.NewMultipartMixed method, which initializes the object as an empty
#  multipart/mixed entity, clearing any existing headers, body, and child parts.  It takes no
#  arguments.

set mime [new_CkMime]

set success [CkMime_NewMultipartMixed $mime]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    exit
}

#  Append child parts.  multipart/mixed is the container for a message body plus attachments.
set bodyPart [new_CkMime]

set success [CkMime_SetBodyFromPlainText $bodyPart "See the attached report."]
if {$success == 0} then {
    puts [CkMime_lastErrorText $bodyPart]
    delete_CkMime $mime
    delete_CkMime $bodyPart
    exit
}

set success [CkMime_AppendPart $mime $bodyPart]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    delete_CkMime $bodyPart
    exit
}

set success [CkMime_AppendPartFromFile $mime "qa_data/report.pdf"]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    delete_CkMime $bodyPart
    exit
}

puts "Number of parts: [CkMime_get_NumParts $mime]"

delete_CkMime $mime
delete_CkMime $bodyPart