Sample code for 30+ languages & platforms
Tcl

Save Email Attachments to Filesystem

Saves email attachments to a directory.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set email [new_CkEmail]

# Load an email object containing attachments.
# This .eml can be downloaded from:
# http://www.example-code.com/testData/HtmlEmail.eml

set success [CkEmail_LoadEml $email "HtmlEmail.eml"]
if {$success != 1} then {
    puts [CkEmail_lastErrorText $email]
    delete_CkEmail $email
    exit
}

# If OverwriteExisting is turned on, files with the same
# name are overwritten.  If turned off, new/unique filenames
# are automatically generated.  The filenames actually saved
# are accessible via the GetAttachmentFilename method.
CkEmail_put_OverwriteExisting $email 1

# Save all attachments to the "myAttachments" subdirectory
# found under the calling process's current working directory.
# This directory is automatically created if it does not already
# exist.
set success [CkEmail_SaveAllAttachments $email "myAttachments"]
if {$success != 1} then {
    puts [CkEmail_lastErrorText $email]
    delete_CkEmail $email
    exit
}

# List the attachment filenames:

for {set i 0} {$i <= [expr [CkEmail_get_NumAttachments $email] - 1]} {incr i} {
    puts [CkEmail_getAttachmentFilename $email $i]
}

delete_CkEmail $email