Sample code for 30+ languages & platforms
C

Transition from MailMan.MxLookupAll to the Chilkat DNS class

Provides instructions for replacing deprecated MxLookupAll method calls with the Chilkat Dns class.

Chilkat C Downloads

C
#include <C_CkMailMan.h>
#include <C_CkStringArray.h>
#include <C_CkDns.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMailMan mailman;
    const char *emailAddr;
    HCkStringArray sa;
    HCkDns dns;
    HCkJsonObject json;
    int i;
    int count_i;
    const char *domain;

    success = FALSE;

    mailman = CkMailMan_Create();

    //  ...
    //  ...

    emailAddr = "joe@example.com";

    //  ------------------------------------------------------------------------
    //  The MxLookupAll method is deprecated:

    sa = CkMailMan_MxLookupAll(mailman,emailAddr);
    if (CkMailMan_getLastMethodSuccess(mailman) == FALSE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        CkMailMan_Dispose(mailman);
        return;
    }

    //  ...
    //  ...

    CkStringArray_Dispose(sa);

    //  ------------------------------------------------------------------------
    //  Do the equivalent using the Chilkat DNS class

    dns = CkDns_Create();

    json = CkJsonObject_Create();

    //  This gets all MX domains for an email address.  (Typically one domain.)
    //  The preferred domain will be at index 0 (see below).
    success = CkDns_Query(dns,"MX",emailAddr,json);
    if (success == FALSE) {
        printf("%s\n",CkDns_lastErrorText(dns));
        CkMailMan_Dispose(mailman);
        CkDns_Dispose(dns);
        CkJsonObject_Dispose(json);
        return;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"answer.mx");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        domain = CkJsonObject_stringOf(json,"answer.mx[i].domain");
        printf("%s\n",domain);
        i = i + 1;
    }



    CkMailMan_Dispose(mailman);
    CkDns_Dispose(dns);
    CkJsonObject_Dispose(json);

    }