Java
Java
Transition from MailMan.MxLookupAll to the Chilkat DNS class
Provides instructions for replacing deprecated MxLookupAll method calls with the Chilkat Dns class.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
CkMailMan mailman = new CkMailMan();
// ...
// ...
String emailAddr = "joe@example.com";
// ------------------------------------------------------------------------
// The MxLookupAll method is deprecated:
CkStringArray sa = mailman.MxLookupAll(emailAddr);
if (mailman.get_LastMethodSuccess() == false) {
System.out.println(mailman.lastErrorText());
return;
}
// ...
// ...
// ------------------------------------------------------------------------
// Do the equivalent using the Chilkat DNS class
CkDns dns = new CkDns();
CkJsonObject json = new CkJsonObject();
// 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",emailAddr,json);
if (success == false) {
System.out.println(dns.lastErrorText());
return;
}
int i = 0;
int count_i = json.SizeOfArray("answer.mx");
while (i < count_i) {
json.put_I(i);
String domain = json.stringOf("answer.mx[i].domain");
System.out.println(domain);
i = i+1;
}
}
}