Unicode C++
Unicode C++
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 Unicode C++ Downloads
#include <CkImapW.h>
#include <CkEmailW.h>
void ChilkatSample(void)
{
bool 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.
CkImapW imap;
imap.put_Ssl(true);
imap.put_Port(993);
success = imap.Connect(L"imap.example.com");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
success = imap.Login(L"user@example.com",L"myPassword");
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
// Build the email to be uploaded.
CkEmailW email;
email.put_Subject(L"Meeting agenda");
email.put_From(L"Alice <alice@example.com>");
success = email.AddTo(L"Bob",L"bob@example.com");
email.put_Body(L"Let's meet at 10am to review the agenda.");
const wchar_t *mimeText = email.getMime();
if (email.get_LastMethodSuccess() == false) {
wprintf(L"%s\n",email.lastErrorText());
return;
}
// Upload to "Archive" with an explicit internal date.
const wchar_t *internalDate = L"Fri, 10 Jul 2026 20:15:30 GMT";
success = imap.AppendMimeWithDateStr(L"Archive",mimeText,internalDate);
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
wprintf(L"Appended UID: %d\n",imap.get_AppendUid());
success = imap.Disconnect();
if (success == false) {
wprintf(L"%s\n",imap.lastErrorText());
return;
}
}