React Native
React Native
Subscribe to an IMAP Mailbox
See more IMAP Examples
Demonstrates the Chilkat Imap.Subscribe method, which subscribes the authenticated IMAP account to a mailbox. Subscription controls which mailboxes are returned by subscribed-mailbox listings. This example subscribes to a mailbox.
Background: An account can have many mailboxes, but a user often cares about only some of them. IMAP's subscription list is that curated set: mail clients typically show subscribed folders by default and hide the rest. Subscribing does not create or change a mailbox — it only adds it to the "show me this one" list (retrieved with a subscribed-only listing).
Unsubscribe removes it from that list.Chilkat React Native Downloads
import { Imap } from '@chilkat/react-native'
async function chilkatExample() {
// Demonstrates the Imap.Subscribe method, which subscribes the authenticated IMAP account to
// a mailbox. Subscription controls which mailboxes are returned by subscribed-mailbox
// listings.
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;
}
// Subscribe to a mailbox.
try {
await imap.subscribeAsync('Archive2026');
} catch {
console.log(imap.lastErrorText);
return;
}
console.log('Subscribed to the mailbox.');
try {
await imap.disconnectAsync();
} catch {
console.log(imap.lastErrorText);
return;
}
}