Sample code for 30+ languages & platforms
React Native

Upload .eml File to an IMAP Mailbox

See more IMAP Examples

Demonstrates how to upload the MIME source of an email to a mailbox on an IMAP server.

Chilkat React Native Downloads

React Native
import { Imap, StringBuilder } from '@chilkat/react-native'

async function chilkatExample() {
  const imap = new Imap();

  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  // Connect to an IMAP server.
  // Use TLS
  imap.ssl = true;
  imap.port = 993;
  try {
    await imap.connectAsync('MY-IMAP-DOMAIN');
  } catch {
    console.log(imap.lastErrorText);
    return;
  }

  // Login
  try {
    await imap.loginAsync('MY-IMAP-LOGIN', 'MY-IMAP-PASSWORD');
  } catch {
    console.log(imap.lastErrorText);
    return;
  }

  const sbMime = new StringBuilder();
  sbMime.loadFile('qa_data/eml/emoji_pizza.eml', 'utf-8');

  // Upload to the mailbox.
  try {
    await imap.appendMimeAsync('[Gmail]/testFolder', sbMime.getAsString());
  } catch {
    console.log(imap.lastErrorText);
    return;
  }

  await imap.disconnectAsync();

  console.log('OK.');
}