JavaScript
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var 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.
var imap = new CkImap();
imap.Ssl = true;
imap.Port = 993;
success = imap.Connect("imap.example.com");
if (success == false) {
console.log(imap.LastErrorText);
return;
}
success = imap.Login("user@example.com","myPassword");
if (success == false) {
console.log(imap.LastErrorText);
return;
}
// Build the email to be uploaded.
var email = new CkEmail();
email.Subject = "Meeting agenda";
email.From = "Alice <alice@example.com>";
success = email.AddTo("Bob","bob@example.com");
email.Body = "Let's meet at 10am to review the agenda.";
var mimeText = email.GetMime();
if (email.LastMethodSuccess == false) {
console.log(email.LastErrorText);
return;
}
// Upload to "Archive" with an explicit internal date.
var internalDate = "Fri, 10 Jul 2026 20:15:30 GMT";
success = imap.AppendMimeWithDateStr("Archive",mimeText,internalDate);
if (success == false) {
console.log(imap.LastErrorText);
return;
}
console.log("Appended UID: " + imap.AppendUid);
success = imap.Disconnect();
if (success == false) {
console.log(imap.LastErrorText);
return;
}