PureBasic
PureBasic
Append MIME and Set the IMAP Internal Date
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithDateStr method, which uploads a MIME message while explicitly setting the server-side internal date. The first argument is the mailbox, the second is the MIME text, and the third is an RFC 822 date/time string (for example Fri, 10 Jul 2026 20:15:30 GMT). This example uploads to Archive with a specific internal date.
Background: The IMAP internal date is mailbox metadata, distinct from the message's own
Date header. It is normally the time the message arrived, and it is what the server uses for SINCE and BEFORE date searches. Setting it explicitly matters when migrating or importing messages, so imported mail keeps its original chronology instead of all appearing to arrive at import time.Chilkat PureBasic Downloads
IncludeFile "CkEmail.pb"
IncludeFile "CkImap.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the Imap.AppendMimeWithDateStr method, which uploads a MIME message and sets
; its server-side internal date. The 1st argument is the mailbox, the 2nd is the MIME text,
; and the 3rd is an RFC 822 date/time string for the internal date.
imap.i = CkImap::ckCreate()
If imap.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkImap::setCkSsl(imap, 1)
CkImap::setCkPort(imap, 993)
success = CkImap::ckConnect(imap,"imap.example.com")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
success = CkImap::ckLogin(imap,"user@example.com","myPassword")
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
ProcedureReturn
EndIf
; Build the email to be uploaded.
email.i = CkEmail::ckCreate()
If email.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkEmail::setCkSubject(email, "Meeting agenda")
CkEmail::setCkFrom(email, "Alice <alice@example.com>")
success = CkEmail::ckAddTo(email,"Bob","bob@example.com")
CkEmail::setCkBody(email, "Let's meet at 10am to review the agenda.")
mimeText.s = CkEmail::ckGetMime(email)
If CkEmail::ckLastMethodSuccess(email) = 0
Debug CkEmail::ckLastErrorText(email)
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
; Upload to "Archive" with an explicit internal date.
internalDate.s = "Fri, 10 Jul 2026 20:15:30 GMT"
success = CkImap::ckAppendMimeWithDateStr(imap,"Archive",mimeText,internalDate)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
Debug "Appended UID: " + Str(CkImap::ckAppendUid(imap))
success = CkImap::ckDisconnect(imap)
If success = 0
Debug CkImap::ckLastErrorText(imap)
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndIf
CkImap::ckDispose(imap)
CkEmail::ckDispose(email)
ProcedureReturn
EndProcedure