Sample code for 30+ languages & platforms
Visual FoxPro

Transition from MailMan.MxLookup to Dns.Query

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

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMailman
LOCAL lcEmailAddr
LOCAL lcDomain
LOCAL loDns
LOCAL loJson
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

loMailman = CreateObject('Chilkat.MailMan')

* ...
* ...

lcEmailAddr = "joe@example.com"

* ------------------------------------------------------------------------
* The MxLookup method is deprecated:

lcDomain = loMailman.MxLookup(lcEmailAddr)
IF (loMailman.LastMethodSuccess = 0) THEN
    ? loMailman.LastErrorText
    RELEASE loMailman
    CANCEL
ENDIF

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

loDns = CreateObject('Chilkat.Dns')

loJson = CreateObject('Chilkat.JsonObject')

* This gets all MX domains for an email address.  (Typically one domain.)
* The preferred domain will be at index 0 (see below).
lnSuccess = loDns.Query("MX",lcEmailAddr,loJson)
IF (lnSuccess = 0) THEN
    ? loDns.LastErrorText
    RELEASE loMailman
    RELEASE loDns
    RELEASE loJson
    CANCEL
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 loMailman
RELEASE loDns
RELEASE loJson