Sample code for 30+ languages & platforms
Android™ Requires Chilkat v11.0.0+

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

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;

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.

    CkEmail wrapper = new CkEmail();
    success = wrapper.LoadEml("forward-as-attachment.eml");
    if (success != true) {
        Log.i(TAG, wrapper.lastErrorText());
        return;
        }

    Log.i(TAG, "Cover note: " + wrapper.subject());
    if (wrapper.get_NumAttachedMessages() == 0) {
        Log.i(TAG, "No attached messages.");
        return;
        }

    CkEmail nested = new CkEmail();
    int i = 0;
    while ((i < wrapper.get_NumAttachedMessages())) {
        success = wrapper.GetAttachedEmail(i,nested);
        if (success != true) {
            Log.i(TAG, wrapper.lastErrorText());
            return;
            }

        Log.i(TAG, "Original author: " + nested.ck_from());
        Log.i(TAG, "Original subject: " + nested.subject());
        Log.i(TAG, "Files on the original: " + String.valueOf(nested.get_NumAttachments()));
        i = i + 1;
        }


  }

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