React Native Requires Chilkat v11.0.0+
React Native
List Email UIDs
List the UIDs of each email in a mailbox.Chilkat React Native Downloads
import { Imap, MessageSet } from '@chilkat/react-native'
async function chilkatExample() {
const imap = new Imap();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Connect to an IMAP server.
// Use TLS
imap.ssl = true;
imap.port = 993;
try {
await imap.connectAsync('MY-IMAP-DOMAIN');
} catch {
console.log(imap.lastErrorText);
return;
}
// Login
try {
await imap.loginAsync('MY-IMAP-LOGIN', 'MY-IMAP-PASSWORD');
} catch {
console.log(imap.lastErrorText);
return;
}
// Select an IMAP mailbox
try {
await imap.selectMailboxAsync('Inbox');
} catch {
console.log(imap.lastErrorText);
return;
}
// Get the message IDs of all the emails in the mailbox
// We can choose to fetch UIDs or sequence numbers.
const fetchUids = true;
const messageSet = new MessageSet();
try {
await imap.queryMbxAsync('ALL', fetchUids, messageSet);
} catch {
console.log(imap.lastErrorText);
return;
}
let i = 0;
const n = messageSet.count;
while (i < n) {
console.log(messageSet.getId(i));
i++;
}
// Disconnect from the IMAP server.
await imap.disconnectAsync();
}