Tcl
Tcl
Append a MIME Message to an IMAP Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMime method, which uploads a complete RFC 822/MIME message to a mailbox. The first argument is the destination mailbox name and the second is the MIME text. This example obtains the MIME from an Email object and uploads it to Drafts.
Background: Use
AppendMime when you already hold a message's raw source — a .eml file, a message you assembled, or one you received. Chilkat sends the text exactly as supplied, without normalizing line endings or re-encoding headers, so every header and MIME boundary is preserved verbatim. The supplied text must be plain text (no raw non-text binary bytes).Chilkat Tcl Downloads
load ./chilkat.dll
set success 0
# Demonstrates the Imap.AppendMime method, which uploads a complete MIME message to a mailbox.
# The 1st argument is the destination mailbox name and the 2nd is the MIME text.
set imap [new_CkImap]
CkImap_put_Ssl $imap 1
CkImap_put_Port $imap 993
set success [CkImap_Connect $imap "imap.example.com"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
set success [CkImap_Login $imap "user@example.com" "myPassword"]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
exit
}
# Build the email to be uploaded.
set email [new_CkEmail]
CkEmail_put_Subject $email "Meeting agenda"
CkEmail_put_From $email "Alice <alice@example.com>"
set success [CkEmail_AddTo $email "Bob" "bob@example.com"]
CkEmail_put_Body $email "Let's meet at 10am to review the agenda."
# Obtain the MIME text to upload. Here it is generated from the Email, but it could equally
# be read from a .eml file.
set mimeText [CkEmail_getMime $email]
if {[CkEmail_get_LastMethodSuccess $email] == 0} then {
puts [CkEmail_lastErrorText $email]
delete_CkImap $imap
delete_CkEmail $email
exit
}
# Append (upload) the MIME to the "Drafts" mailbox.
set success [CkImap_AppendMime $imap "Drafts" $mimeText]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkEmail $email
exit
}
puts "Appended UID: [CkImap_get_AppendUid $imap]"
set success [CkImap_Disconnect $imap]
if {$success == 0} then {
puts [CkImap_lastErrorText $imap]
delete_CkImap $imap
delete_CkEmail $email
exit
}
delete_CkImap $imap
delete_CkEmail $email