React Native Requires Chilkat v11.0.0+
React Native
Secure IMAP over TLS/SSL
To communicate with an IMAP server over TLS/SSL, simply set the Ssl and Port properties. The remainder of your code is the same as with non-SSL.Chilkat React Native Downloads
import { Email, EmailBundle, Imap, MessageSet } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const imap = new Imap();
// To use a secure TLS/SSL connection, set the Ssl property and the port:
imap.ssl = true;
// The typical port for IMAP SSL is 993
imap.port = 993;
// Connect to an IMAP server.
try {
await imap.connectAsync('imap.example.com');
} catch {
console.log(imap.lastErrorText);
return;
}
// Login
try {
await imap.loginAsync('myLogin', 'myPassword');
} 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
const fetchUids = true;
const messageSet = new MessageSet();
try {
await imap.queryMbxAsync('ALL', fetchUids, messageSet);
} catch {
console.log(imap.lastErrorText);
return;
}
// Fetch the emails into a bundle object:
const bundle = new EmailBundle();
const headersOnly = false;
try {
await imap.fetchMsgSetAsync(headersOnly, messageSet, bundle);
} catch {
console.log(imap.lastErrorText);
return;
}
// Loop over the bundle and display the FROM and SUBJECT of each.
const email = new Email();
let i = 0;
const numEmails = bundle.messageCount;
while (i < numEmails) {
bundle.emailAt(i, email);
console.log(email.from);
console.log(email.subject);
console.log('--');
i++;
}
// Disconnect from the IMAP server.
await imap.disconnectAsync();
}