Sample code for 30+ languages & platforms
Unicode C

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 Unicode C Downloads

Unicode C
#include <C_CkEmailW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmailW email;
    HCkJsonObjectW json;

    success = FALSE;

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

    email = CkEmailW_Create();

    success = CkEmailW_LoadEml(email,L"qa_data/eml/dsn_bounce.eml");
    if (success == FALSE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        return true;
    }

    //  Only meaningful for a multipart/report email.
    if (CkEmailW_IsMultipartReport(email) == TRUE) {
        json = CkJsonObjectW_Create();
        success = CkEmailW_GetDsnInfo(email,json);
        if (success == TRUE) {
            wprintf(L"%s\n",CkJsonObjectW_emit(json));
        }

    }
    else {
        wprintf(L"This email is not a multipart/report.\n");
    }

    //  Note: The path "qa_data/..." is a relative local filesystem path,
    //  relative to the current working directory of the running application.


    CkEmailW_Dispose(email);
    CkJsonObjectW_Dispose(json);

    }