Sample code for 30+ languages & platforms
C

Example: Email.GetDsnInfo method

See more Email Object Examples

Demonstrates how to call the GetDsnInfo method.

Chilkat C Downloads

C
#include <C_CkEmail.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkEmail email;
    HCkJsonObject json;
    const char *strVal;
    const char *reporting_mta;
    const char *action;
    const char *status;
    const char *remote_mta;
    const char *x_supplementary_info;
    const char *x_display_name;
    int i;
    int count;

    success = FALSE;

    email = CkEmail_Create();

    success = CkEmail_LoadEml(email,"qa_data/eml/sample_multipart_report.eml");
    if (success == FALSE) {
        printf("%s\n",CkEmail_lastErrorText(email));
        CkEmail_Dispose(email);
        return;
    }

    json = CkJsonObject_Create();
    success = CkEmail_GetDsnInfo(email,json);
    if (success == FALSE) {
        printf("%s\n",CkEmail_lastErrorText(email));
        CkEmail_Dispose(email);
        CkJsonObject_Dispose(json);
        return;
    }

    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_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 = CkJsonObject_stringOf(json,"reporting-mta");
    action = CkJsonObject_stringOf(json,"action");
    status = CkJsonObject_stringOf(json,"status");
    remote_mta = CkJsonObject_stringOf(json,"remote-mta");
    x_supplementary_info = CkJsonObject_stringOf(json,"x-supplementary-info");
    x_display_name = CkJsonObject_stringOf(json,"x-display-name");
    i = 0;
    count = CkJsonObject_SizeOfArray(json,"final-recipient");
    while (i < count) {
        CkJsonObject_putI(json,i);
        strVal = CkJsonObject_stringOf(json,"final-recipient[i]");
        i = i + 1;
    }



    CkEmail_Dispose(email);
    CkJsonObject_Dispose(json);

    }