Sample code for 30+ languages & platforms
Android™

Get Delivery-Status Info as JSON

See more Email Object Examples

Demonstrates the Chilkat Email.GetDsnInfo method, which — when IsMultipartReport indicates the email is a multipart/report — obtains the delivery-status information as a JsonObject. This example loads a bounce message, confirms it is a report, and prints the extracted DSN details as JSON.

Background: A bounce (DSN) carries its key facts — which recipient failed, the status code, the reporting server — in a machine-readable message/delivery-status part. Rather than parsing those raw fields yourself, GetDsnInfo gathers them into a structured JSON document you can query with the JsonObject API, making it easy to automate bounce handling and prune failed addresses from a mailing list.

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 GetDsnInfo method, which, for a multipart/report email, obtains the
    //  delivery-status information as a JSON object.

    CkEmail email = new CkEmail();

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

    //  Only meaningful for a multipart/report email.
    if (email.IsMultipartReport() == true) {
        CkJsonObject json = new CkJsonObject();
        success = email.GetDsnInfo(json);
        if (success == true) {
            Log.i(TAG, json.emit());
            }

        }
    else {
        Log.i(TAG, "This email is not a multipart/report.");
        }

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