Sample code for 30+ languages & platforms
React Native

Connecting to GMAIL using IMAP

Demonstrates how to connect to GMAIL using IMAP.

Chilkat React Native Downloads

React Native
import { Imap } 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();

  // Turn on session logging:
  imap.keepSessionLog = true;

  // Connect to GMail
  // Use TLS
  imap.ssl = true;
  imap.port = 993;
  try {
    await imap.connectAsync('imap.gmail.com');
  } catch {
    console.log(imap.lastErrorText);
    return;
  }

  // Login
  // Your login is typically your GMail email address.
  try {
    await imap.loginAsync('username@gmail.com', 'myPassword');
  } catch {
    console.log(imap.lastErrorText);
    return;
  }

  // Select an IMAP mailbox
  try {
    await imap.selectMailboxAsync('Inbox');
  } catch {
    console.log(imap.lastErrorText);
    return;
  }

  // Show the session log.
  console.log(imap.sessionLog);

  // Disconnect from the IMAP server.
  await imap.disconnectAsync();
}