React Native Requires Chilkat v11.0.0+
React Native
IMAP using SOCKS5, SOCKS4 Proxy
Demonstrates how to connect to an IMAP server through a SOCKS5 or SOCKS4 proxy.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 SOCKS4 or SOCKS5 proxy, simply set the following
// properties prior to connecting with the IMAP server:
// The SOCKS hostname may be a domain name or
// IP address:
imap.socksHostname = 'www.mysocksproxyserver.com';
imap.socksPort = 1080;
imap.socksUsername = 'myProxyLogin';
imap.socksPassword = 'myProxyPassword';
// Set the SOCKS version to 4 or 5 based on the version
// of the SOCKS proxy server:
imap.socksVersion = 5;
// Note: SOCKS4 servers only support usernames without passwords.
// SOCKS5 servers support full login/password authentication.
// Connect to an IMAP server through the SOCKS proxy.
// Use TLS
imap.ssl = true;
imap.port = 993;
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
// 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;
}
// 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();
}