Sample code for 30+ languages & platforms
Android™

Remove All Attached Messages from an Email

See more Email Object Examples

Demonstrates the Chilkat Email.RemoveAttachedMessages method, which removes all message/rfc822 sub-parts (attached emails) from the object at once. Ordinary file attachments and related HTML resources are left unchanged. This example attaches two emails, removes them all, and prints the count before and after.

Background: This is the "remove them all" companion to RemoveAttachedMessage. Because it touches only the nested-message parts, you can strip forwarded originals or a digest's members while preserving the message body, its inline images, and any regular attachments — a clean way to keep the carrier message while discarding what it enclosed.

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);

    //  Demonstrates the RemoveAttachedMessages method, which removes all message/rfc822
    //  sub-parts (attached emails) from the email at once.  Ordinary file attachments and
    //  related items are not affected.

    CkEmail inner1 = new CkEmail();
    inner1.put_Subject("Embedded 1");

    CkEmail inner2 = new CkEmail();
    inner2.put_Subject("Embedded 2");

    CkEmail email = new CkEmail();
    email.put_Subject("Has attached messages");
    email.AttachEmail(inner1);
    email.AttachEmail(inner2);

    Log.i(TAG, "NumAttachedMessages before = " + String.valueOf(email.get_NumAttachedMessages()));

    //  Remove all attached messages.
    email.RemoveAttachedMessages();

    Log.i(TAG, "NumAttachedMessages after = " + String.valueOf(email.get_NumAttachedMessages()));

  }

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