Sample code for 30+ languages & platforms
React Native

Iterate Email Headers

Demonstrates how to iterate over the email header fields.

Chilkat React Native Downloads

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

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

  // First, load an email from a file. 
  // Note: an email object may be loaded from a file, or
  // downloaded directly from a POP3 or IMAP server...

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

  // How many header fields?
  const n = email.numHeaderFields;
  if (n > 0) {

    // Display the name and value of each header:
    let name = '';
    let value = '';
    for (let i = 0; i < n; i++) {
      name = email.getHeaderFieldName(i);
      value = email.getHeaderFieldValue(i);
      console.log(i);
      console.log(name);
      console.log(value);
    }
  }
}