Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL loEmail
LOCAL lcMimeText
LOCAL lcInternalDate

lnSuccess = 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.

loImap = CreateObject('Chilkat.Imap')

loImap.Ssl = 1
loImap.Port = 993

lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

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

lcMimeText = loEmail.GetMime()
IF (loEmail.LastMethodSuccess = 0) THEN
    ? loEmail.LastErrorText
    RELEASE loImap
    RELEASE loEmail
    CANCEL
ENDIF

*  Upload to "Archive" with an explicit internal date.
lcInternalDate = "Fri, 10 Jul 2026 20:15:30 GMT"
lnSuccess = loImap.AppendMimeWithDateStr("Archive",lcMimeText,lcInternalDate)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loEmail
    CANCEL
ENDIF

? "Appended UID: " + STR(loImap.AppendUid)

lnSuccess = loImap.Disconnect()
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loEmail
    CANCEL
ENDIF

RELEASE loImap
RELEASE loEmail