Sample code for 30+ languages & platforms
React Native

Attach Email as message/rfc822 sub-part to an Email

See more Email Object Examples

Demonstrates how to add attach a message/rfc822 email to another email.

Chilkat React Native Downloads

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

function chilkatExample() {
  // In this example, we'll attach an email loaded from a .eml file to a new email.

  const fac = new FileAccess();
  const emlBytes = fac.readEntireFile('qa_data/eml/simple.eml');

  const email = new Email();
  email.subject = 'This is a test email with an attached email.';
  email.body = 'Test with attached email.';
  email.addTo('Joe', 'joe@example.com');
  email.from = 'mary@example.com';

  email.attachMessage(emlBytes);

  console.log(email.getMime());

  // ----------------------------------------------------------------------
  // Alternatively, we could do this:
  const emailToBeAttached = new Email();
  emailToBeAttached.loadEml('qa_data/eml/simple.eml');

  const email2 = new Email();
  email2.subject = 'This is a test email with an attached email.';
  email2.body = 'Test with attached email.';
  email2.addTo('Joe', 'joe@example.com');
  email2.from = 'mary@example.com';

  const emlBytes2 = emailToBeAttached.getMimeBinary();
  email2.attachMessage(emlBytes2);

  console.log('----');

  console.log(email2.getMime());
}