DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoImap
Handle hoEmail
String sMimeText
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatImap)) To hoImap
If (Not(IsComObjectCreated(hoImap))) Begin
Send CreateComObject of hoImap
End
Set ComSsl Of hoImap To True
Set ComPort Of hoImap To 993
Get ComConnect Of hoImap "imap.example.com" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
// Build the email to be uploaded.
Get Create (RefClass(cComChilkatEmail)) To hoEmail
If (Not(IsComObjectCreated(hoEmail))) Begin
Send CreateComObject of hoEmail
End
Set ComSubject Of hoEmail To "Meeting agenda"
Set ComFrom Of hoEmail To "Alice <alice@example.com>"
Get ComAddTo Of hoEmail "Bob" "bob@example.com" To iSuccess
Set ComBody Of hoEmail To "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.
Get ComGetMime Of hoEmail To sMimeText
Get ComLastMethodSuccess Of hoEmail To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoEmail To sTemp1
Showln sTemp1
Procedure_Return
End
// Append (upload) the MIME to the "Drafts" mailbox.
Get ComAppendMime Of hoImap "Drafts" sMimeText To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComAppendUid Of hoImap To iTemp1
Showln "Appended UID: " iTemp1
Get ComDisconnect Of hoImap To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
End_Procedure