React Native
React Native
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 React Native Downloads
import { Email, Imap } from '@chilkat/react-native'
async function chilkatExample() {
// 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.
const imap = new Imap();
imap.ssl = true;
imap.port = 993;
try {
await imap.connectAsync('imap.example.com');
} catch {
console.log(imap.lastErrorText);
return;
}
try {
await imap.loginAsync('user@example.com', 'myPassword');
} catch {
console.log(imap.lastErrorText);
return;
}
// Build the email to be uploaded.
const email = new Email();
email.subject = 'Meeting agenda';
email.from = 'Alice <alice@example.com>';
email.addTo('Bob', 'bob@example.com');
email.body = 'Let\'s meet at 10am to review the agenda.';
let mimeText: string;
try {
mimeText = email.getMime();
} catch {
console.log(email.lastErrorText);
return;
}
// Upload to "Archive" with an explicit internal date.
const internalDate = 'Fri, 10 Jul 2026 20:15:30 GMT';
try {
await imap.appendMimeWithDateStrAsync('Archive', mimeText, internalDate);
} catch {
console.log(imap.lastErrorText);
return;
}
console.log(`Appended UID: ${imap.appendUid}`);
try {
await imap.disconnectAsync();
} catch {
console.log(imap.lastErrorText);
return;
}
}