Sample code for 30+ languages & platforms
React Native

Unpack HTML Email to Files

Unpacks an HTML email into an HTML file and related files (images and style sheets). The links within the HTML are updated to point to the files unpacked and saved to disk.

Chilkat React Native Downloads

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

function chilkatExample() {
  const email = new Email();

  try {
    email.loadEml('qa_data/eml/happyHour.eml');
  } catch {
    console.log(email.lastErrorText);
    return;
  }

  // Is this an HTML email?
  if (email.hasHtmlBody()) {

    // Unpack the HTML to files.  The image and css URLs
    // in the HTML are modified to point to the files extracted to disk.
    const unpackDir = 'qa_output/emails';
    const partsSubdir = 'images';
    const htmlFilename = 'happyHour.html';
    try {
      email.unpackHtml(unpackDir, htmlFilename, partsSubdir);
    } catch {
      console.log(email.lastErrorText);
      return;
    }

    console.log('Success.');
  }
}