Sample code for 30+ languages & platforms
Android™

Access Attached Message (Embedded Email)

How to access an email embedded within another email (i.e. an attached message).

Chilkat Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    boolean success = false;

    CkEmail email = new CkEmail();

    // Load an email from a .eml
    success = email.LoadEml("embeddedEmail.eml");
    if (success == false) {
        Log.i(TAG, email.lastErrorText());
        return;
        }

    // Display how many attached emails are embedded within
    // this one:
    int numAttached = email.get_NumAttachedMessages();
    Log.i(TAG, "numAttached = " + String.valueOf(numAttached));

    // Get the 1st attached message.
    CkEmail email2 = new CkEmail();
    success = email.GetAttachedEmail(0,email2);
    if (success == true) {

        // Display the subject, From, and a header field...
        Log.i(TAG, email2.subject());
        Log.i(TAG, email2.ck_from());
        Log.i(TAG, email2.getHeaderField("X-SOMETHING"));
        }


  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}