Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oImap
LOCAL oEmail
LOCAL cMimeText
LOCAL cInternalDate

nSuccess := 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.

oImap := CreateObject("Chilkat.Imap")

oImap:Ssl := 1
oImap:Port := 993

nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

nSuccess := oImap:Login("user@example.com", "myPassword")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Build the email to be uploaded.
oEmail := CreateObject("Chilkat.Email")
oEmail:Subject := "Meeting agenda"
oEmail:From := "Alice <alice@example.com>"
nSuccess := oEmail:AddTo("Bob", "bob@example.com")
oEmail:Body := "Let's meet at 10am to review the agenda."

cMimeText := oEmail:GetMime()
IF (oEmail:LastMethodSuccess == 0)
    ? oEmail:LastErrorText
    oImap:destroy()
    oEmail:destroy()
    RETURN
ENDIF

//  Upload to "Archive" with an explicit internal date.
cInternalDate := "Fri, 10 Jul 2026 20:15:30 GMT"
nSuccess := oImap:AppendMimeWithDateStr("Archive", cMimeText, cInternalDate)
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    oEmail:destroy()
    RETURN
ENDIF

? "Appended UID: " + Str(oImap:AppendUid)

nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    oEmail:destroy()
    RETURN
ENDIF

oImap:destroy()
oEmail:destroy()