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

Download POP3 Email to MIME

Download the email from a POP3 mailbox directly into MIME, without parsing into email objects.

Chilkat React Native Downloads

React Native
import { BinData, Email, MailMan, StringTable } 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.example.com';

  // Set the POP3 login/password.
  mailman.popUsername = 'myLogin';
  mailman.popPassword = 'myPassword';

  // First, get the complete set of UIDLs for the email in the POP3 mailbox:
  const stUidls = new StringTable();
  try {
    await mailman.fetchUidlsAsync(stUidls);
  } catch {
    console.log(mailman.lastErrorText);
    return;
  }

  // Download each email as MIME.
  // If desired, the MIME can be loaded into an email object.
  const bdMime = new BinData();
  const email = new Email();

  const count = stUidls.count;
  let i = 0;
  while (i < count) {
    try {
      await mailman.fetchMimeBdAsync(stUidls.stringAt(i), bdMime);
    } catch {
      console.log(mailman.lastErrorText);
      return;
    }

    email.setFromMimeBd(bdMime);
    console.log(`From: ${email.from}`);
    console.log(`Subject: ${email.subject}`);

    i++;
  }
}