Sample code for 30+ languages & platforms
React Native Requires Chilkat v11.0.0+

POP3 STARTTLS

Demonstrates how to do POP3 STARTTLS.

Chilkat React Native Downloads

React Native
import { Email, EmailBundle, MailMan } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  // The mailman object is used for receiving (POP3) 
  // and sending (SMTP) email.
  const mailman = new MailMan();

  // Set the POP3 server's hostname
  mailman.mailHost = 'pop.gmail.com';

  // Set the POP3 login/password.
  mailman.popUsername = '****@gmail.com';
  mailman.popPassword = '****';

  // Indicate that we want TLS/SSL.  Also, set the port to 995:
  mailman.mailPort = 995;
  mailman.popSsl = true;

  const bundle = new EmailBundle();
  const keepOnServer = true;
  const headersOnly = false;
  // Irrelevent because we are NOT downloading headers-only
  const numBodyLines = 0;
  try {
    await mailman.fetchAllAsync(keepOnServer, headersOnly, numBodyLines, bundle);
  } catch {
    console.log(mailman.lastErrorText);
    return;
  }

  const email = new Email();
  let i = 0;
  while (i < bundle.messageCount) {
    bundle.emailAt(i, email);

    // Display the From email address and the subject.
    console.log(`From: ${email.from}`);
    console.log(`Subject: ${email.subject}`);
    i++;
  }
}