Sample code for 30+ languages & platforms
Tcl

Convert 8-bit MIME Parts to Base64

See more MIME Examples

Demonstrates the Chilkat Mime.Convert8Bit method, which recursively converts every part whose Content-Transfer-Encoding is 8bit or binary to base64. It takes no arguments and is a void method.

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: The original SMTP standard only guaranteed 7-bit transport, and some legacy servers still reject or mangle raw 8-bit and binary content. Converting those parts to base64 — a 7-bit-safe encoding — makes the whole message safe to relay through such systems without loss. It walks the entire tree, so a multipart message with several offending parts is fixed in one call.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set mime [new_CkMime]

set success [CkMime_LoadMimeFile $mime "qa_data/message.eml"]
if {$success == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    exit
}

#  Recursively convert every part whose Content-Transfer-Encoding is 8bit or binary to base64.
#  This makes the MIME safe to transmit over channels that only support 7-bit text (such as some
#  legacy SMTP servers).
CkMime_Convert8Bit $mime

puts "8bit/binary parts converted to base64."
set mimeText [CkMime_getMime $mime]
if {[CkMime_get_LastMethodSuccess $mime] == 0} then {
    puts [CkMime_lastErrorText $mime]
    delete_CkMime $mime
    exit
}

puts "$mimeText"

delete_CkMime $mime