Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oDns
LOCAL oJson
LOCAL cEmailAddr
LOCAL i
LOCAL nCount_i
LOCAL cDomain
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oDns := CreateObject("Chilkat.Dns")
oJson := CreateObject("Chilkat.JsonObject")
cEmailAddr := "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).
nSuccess := oDns:Query("MX", cEmailAddr, oJson)
IF (nSuccess == 0)
? oDns:LastErrorText
oDns:destroy()
oJson:destroy()
RETURN
ENDIF
i := 0
nCount_i := oJson:SizeOfArray("answer.mx")
DO WHILE i < nCount_i
oJson:I := i
cDomain := oJson:StringOf("answer.mx[i].domain")
? cDomain
i := i + 1
ENDDO
oDns:destroy()
oJson:destroy()