Sample code for 30+ languages & platforms
Android™

Load an Email from a .eml File

See more Email Object Examples

Demonstrates the Chilkat Email.LoadEml method, which loads a complete email from an .eml file. An EML file contains RFC822/MIME message text. On success, the loaded message replaces the entire current email — recipients, headers, bodies, related items, and attachments. This example loads an EML and reads its subject and from.

Background: .eml is the standard on-disk format for a single email — it is simply the raw MIME saved to a file, which most mail clients can export and open. LoadEml parses that MIME into a fully populated Email object, giving you programmatic access to every part. It is the natural counterpart to SaveEml.

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;

    //  Demonstrates the LoadEml method, which loads a complete email from an .eml file (an EML
    //  file contains RFC822/MIME message text).  On success, the loaded message replaces the
    //  entire current email.

    CkEmail email = new CkEmail();

    success = email.LoadEml("qa_data/eml/message.eml");
    if (success == false) {
        Log.i(TAG, email.lastErrorText());
        return true;
        }

    Log.i(TAG, "Subject: " + email.subject());
    Log.i(TAG, "From: " + email.ck_from());

    //  Note: The path "qa_data/..." is a relative local filesystem path,
    //  relative to the current working directory of the running application.

  }

  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."
  }
}