Sample code for 30+ languages & platforms
Android™

Count the Report Parts in a multipart/report Email

See more Email Object Examples

Demonstrates the read-only Chilkat Email.NumReports property, which is the number of report parts in a multipart/report email. A part is counted as a report when its Content-Type is message/* (except message/rfc822) or text/rfc822-headers. Use GetReport to retrieve the body of each report part; indexes are zero-based. This example loads a report email and prints each report part.

Background: When a message can't be delivered, the mail system usually sends back a bounce known as a Delivery Status Notification (DSN). DSNs use the multipart/report structure, which bundles several parts: a human-readable explanation, a machine-readable message/delivery-status part describing exactly what happened (recipient, status code, failing server), and often the original message's headers. Reading these report parts lets a program automatically detect and process bounces.

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 read-only Email.NumReports property, which is the number of report
    //  parts in a multipart/report email (for example, a Delivery Status Notification).
    //  Use GetReport to retrieve the body of each report part.  Indexes are zero-based.

    CkEmail email = new CkEmail();

    //  Load a multipart/report email (such as a bounce / DSN message).
    success = email.LoadEml("qa_data/eml/dsn_bounce.eml");
    if (success == false) {
        Log.i(TAG, email.lastErrorText());
        return true;
        }

    int n = email.get_NumReports();
    Log.i(TAG, "NumReports = " + String.valueOf(n));

    int i;
    for (i = 0; i <= n - 1; i++) {
        Log.i(TAG, "---- Report " + String.valueOf(i) + " ----");
        Log.i(TAG, email.getReport(i));
        }


  }

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