Go
Go
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 Go Downloads
success := false
// 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 := chilkat.NewImap()
imap.SetSsl(true)
imap.SetPort(993)
success = imap.Connect("imap.example.com")
if success == false {
fmt.Println(imap.LastErrorText())
imap.DisposeImap()
return
}
success = imap.Login("user@example.com","myPassword")
if success == false {
fmt.Println(imap.LastErrorText())
imap.DisposeImap()
return
}
// Build the email to be uploaded.
email := chilkat.NewEmail()
email.SetSubject("Meeting agenda")
email.SetFrom("Alice <alice@example.com>")
success = email.AddTo("Bob","bob@example.com")
email.SetBody("Let's meet at 10am to review the agenda.")
mimeText := email.GetMime()
if email.LastMethodSuccess() == false {
fmt.Println(email.LastErrorText())
imap.DisposeImap()
email.DisposeEmail()
return
}
// Upload to "Archive" with an explicit internal date.
internalDate := "Fri, 10 Jul 2026 20:15:30 GMT"
success = imap.AppendMimeWithDateStr("Archive",*mimeText,internalDate)
if success == false {
fmt.Println(imap.LastErrorText())
imap.DisposeImap()
email.DisposeEmail()
return
}
fmt.Println("Appended UID: ", imap.AppendUid())
success = imap.Disconnect()
if success == false {
fmt.Println(imap.LastErrorText())
imap.DisposeImap()
email.DisposeEmail()
return
}
imap.DisposeImap()
email.DisposeEmail()