Sample code for 30+ languages & platforms
React Native

Upload (Append) Email to an IMAP Mailbox

Upload / append an email to an IMAP mailbox.

Chilkat React Native Downloads

React Native
import { Email, 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();

  // Connect to an IMAP server.
  // 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;
  }

  const email = new Email();

  // Load the email from a .eml file.
  try {
    email.loadEml('myEmail.eml');
  } catch {
    console.log(email.lastErrorText);
    return;
  }

  try {
    await imap.appendMailAsync('Inbox', email);
  } catch {
    console.log(imap.lastErrorText);
    return;
  }

  console.log('Email uploaded to Inbox!');

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