Sample code for 30+ languages & platforms
Objective-C

Transition from MailMan.MxLookup to Dns.Query

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

Chilkat Objective-C Downloads

Objective-C
#import <CkoMailMan.h>
#import <NSString.h>
#import <CkoDns.h>
#import <CkoJsonObject.h>

BOOL success = NO;

CkoMailMan *mailman = [[CkoMailMan alloc] init];

//  ...
//  ...

NSString *emailAddr = @"joe@example.com";

//  ------------------------------------------------------------------------
//  The MxLookup method is deprecated:

NSString *domain = [mailman MxLookup: emailAddr];
if (mailman.LastMethodSuccess == NO) {
    NSLog(@"%@",mailman.LastErrorText);
    return;
}

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

CkoDns *dns = [[CkoDns alloc] init];

CkoJsonObject *json = [[CkoJsonObject alloc] init];

//  This gets all MX domains for an email address.  (Typically one domain.)
//  The preferred domain will be at index 0 (see below).
success = [dns Query: @"MX" domain: emailAddr answer: json];
if (success == NO) {
    NSLog(@"%@",dns.LastErrorText);
    return;
}

int i = 0;
int count_i = [[json SizeOfArray: @"answer.mx"] intValue];
while (i < count_i) {
    json.I = [NSNumber numberWithInt: i];
    domain = [json StringOf: @"answer.mx[i].domain"];
    NSLog(@"%@",domain);
    i = i + 1;
}