PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_Email
string ls_MimeText
string ls_InternalDate
li_Success = 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.
loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
destroy loo_Imap
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// Build the email to be uploaded.
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
loo_Email.Subject = "Meeting agenda"
loo_Email.From = "Alice <alice@example.com>"
li_Success = loo_Email.AddTo("Bob","bob@example.com")
loo_Email.Body = "Let's meet at 10am to review the agenda."
ls_MimeText = loo_Email.GetMime()
if loo_Email.LastMethodSuccess = 0 then
Write-Debug loo_Email.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
// Upload to "Archive" with an explicit internal date.
ls_InternalDate = "Fri, 10 Jul 2026 20:15:30 GMT"
li_Success = loo_Imap.AppendMimeWithDateStr("Archive",ls_MimeText,ls_InternalDate)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
Write-Debug "Appended UID: " + string(loo_Imap.AppendUid)
li_Success = loo_Imap.Disconnect()
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Email
return
end if
destroy loo_Imap
destroy loo_Email