Sample code for 30+ languages & platforms
Unicode C

Example: Email.GetDsnInfo method

See more Email Object Examples

Demonstrates how to call the GetDsnInfo method.

Chilkat Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmailW email;
    HCkJsonObjectW json;
    const wchar_t *strVal;
    const wchar_t *reporting_mta;
    const wchar_t *action;
    const wchar_t *status;
    const wchar_t *remote_mta;
    const wchar_t *x_supplementary_info;
    const wchar_t *x_display_name;
    int i;
    int count;

    success = FALSE;

    email = CkEmailW_Create();

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

    json = CkJsonObjectW_Create();
    success = CkEmailW_GetDsnInfo(email,json);
    if (success == FALSE) {
        wprintf(L"%s\n",CkEmailW_lastErrorText(email));
        CkEmailW_Dispose(email);
        CkJsonObjectW_Dispose(json);
        return;
    }

    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    //  Sample output:

    //  {
    //    "reporting-mta": "dns; Exchange2016.example.com",
    //    "final-recipient": [
    //      "herb.butterworth1247692846@gmail.com"
    //    ],
    //    "action": "failed",
    //    "status": "5.1.1",
    //    "remote-mta": "dns; mx.google.com",
    //    "x-supplementary-info": "<mx.google.com #5.1.1 smtp;550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1  https://support.google.com/mail/?p=NoSuchUser o8-20020a056870968800b001b55816bea9si2188132oaq.70 - gsmtp>",
    //    "x-display-name": "herb.butterworth1247692846@gmail.com"
    //  }

    //  Code for parsing the JSON:

    reporting_mta = CkJsonObjectW_stringOf(json,L"reporting-mta");
    action = CkJsonObjectW_stringOf(json,L"action");
    status = CkJsonObjectW_stringOf(json,L"status");
    remote_mta = CkJsonObjectW_stringOf(json,L"remote-mta");
    x_supplementary_info = CkJsonObjectW_stringOf(json,L"x-supplementary-info");
    x_display_name = CkJsonObjectW_stringOf(json,L"x-display-name");
    i = 0;
    count = CkJsonObjectW_SizeOfArray(json,L"final-recipient");
    while (i < count) {
        CkJsonObjectW_putI(json,i);
        strVal = CkJsonObjectW_stringOf(json,L"final-recipient[i]");
        i = i + 1;
    }



    CkEmailW_Dispose(email);
    CkJsonObjectW_Dispose(json);

    }