React Native Requires Chilkat v11.0.0+
React Native
IMAP STARTTLS (Explicit TLS/SSL)
The StartTls property is set to force the Connect method to automatically convert an connection to TLS/SSL via the STARTTLS IMAP command.This is also known as "explicit TLS/SSL" as opposed to "implicit TLS/SSL". With implicit TLS/SSL, the IMAP client connects on the well-known IMAP TLS/SSL port 993 and the secure channel is immediately established. With explicit TLS/SSL, the IMAP client connects on the typical non-secure port (143 usually) and the converts the connection via the STARTTLS command.
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();
// Indicate that STARTTLS should be used to convert
// to a secure TLS/SSL connection:
imap.startTls = true;
imap.port = 143;
// Connect to an IMAP server and convert the connection
// to TLS/SSL via STARTTLS.
try {
await imap.connectAsync('imap.example.com');
} catch {
console.log(imap.lastErrorText);
return;
}
// The remainder of this example is the same as for
// non-TLS/SSL...
// 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();
}