Sample code for 30+ languages & platforms
Java

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 Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Email;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

    public static void main(String[] args) {
        boolean success = false;

        // Demonstrates the GetDsnInfo method, which, for a multipart/report email, obtains the
        // delivery-status information as a JSON object.

        Email email = new Email();

        try {
            email.loadEml("qa_data/eml/dsn_bounce.eml");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Only meaningful for a multipart/report email.
        if (email.isMultipartReport()) {
            JsonObject json = new JsonObject();
            try {
                email.getDsnInfo(json);
                success = true;
            } catch (ChilkatException e) {
                success = false;
            }
            if (success) {
                System.out.println(json.emit());
            }
        } else {
            System.out.println("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.
    }
}