Android™
Android™
MX Lookup Mail Server Domain by Email Address
How to find the mail server for a given email address. Returns the domain name of the primary mail server.Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkDns dns = new CkDns();
CkJsonObject json = new CkJsonObject();
String emailAddr = "bob@example.com";
// 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) {
Log.i(TAG, 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");
Log.i(TAG, domain);
i = i + 1;
}
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}