(Lianja) 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. Note: This example requires Chilkat v11.0.0 or greater.
llSuccess = .F.
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loDns = createobject("CkDns")
loJson = createobject("CkJsonObject")
lcEmailAddr = "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).
llSuccess = loDns.Query("MX",lcEmailAddr,loJson)
if (llSuccess = .F.) then
? loDns.LastErrorText
release loDns
release loJson
return
endif
i = 0
lnCount_i = loJson.SizeOfArray("answer.mx")
do while i < lnCount_i
loJson.I = i
lcDomain = loJson.StringOf("answer.mx[i].domain")
? lcDomain
i = i + 1
enddo
release loDns
release loJson
|