DataFlex
DataFlex
Append MIME from a StringBuilder with Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a StringBuilder and sets its initial system flags. The first argument is the mailbox, the second is the StringBuilder, and the third through sixth set \Seen, \Flagged, \Answered, and \Draft. This example uploads to Drafts with the draft flag set.
Background: This is the
StringBuilder form of AppendMimeWithFlags. Passing the MIME as a StringBuilder avoids copying a large message into an intermediate string and is convenient when you already built or loaded the message into a StringBuilder (for example with LoadFile).Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoImap
Handle hoEmail
String sMimeText
Variant vSbMime
Handle hoSbMime
Boolean iSeen
Boolean iFlagged
Boolean iAnswered
Boolean iDraft
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// Demonstrates the Imap.AppendMimeWithFlagsSb method, which uploads MIME contained in a
// StringBuilder and sets its initial system flags. The 1st argument is the mailbox, the 2nd
// is the StringBuilder, and the 3rd through 6th set \Seen, \Flagged, \Answered, and \Draft.
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."
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
// Load the MIME into a StringBuilder. (A StringBuilder can also be filled via LoadFile.)
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbMime
If (Not(IsComObjectCreated(hoSbMime))) Begin
Send CreateComObject of hoSbMime
End
Get ComAppend Of hoSbMime sMimeText To iSuccess
// Choose the initial flags. Named variables make each argument's meaning clear at the call.
Move False To iSeen
Move False To iFlagged
Move False To iAnswered
Move True To iDraft
// Upload to "Drafts" with the \Draft flag set.
Get pvComObject of hoSbMime to vSbMime
Get ComAppendMimeWithFlagsSb Of hoImap "Drafts" vSbMime iSeen iFlagged iAnswered iDraft 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