PureBasic Requires Chilkat v11.0.0+
PureBasic
Transition from MailMan.MxLookup to Dns.Query
Provides instructions for replacing deprecated MxLookup method calls with the Chilkat Dns class.Chilkat PureBasic Downloads
IncludeFile "CkJsonObject.pb"
IncludeFile "CkDns.pb"
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 0
mailman.i = CkMailMan::ckCreate()
If mailman.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; ...
; ...
emailAddr.s = "joe@example.com"
; ------------------------------------------------------------------------
; The MxLookup method is deprecated:
domain.s = CkMailMan::ckMxLookup(mailman,emailAddr)
If CkMailMan::ckLastMethodSuccess(mailman) = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndIf
; ------------------------------------------------------------------------
; Do the equivalent using the Chilkat DNS class
dns.i = CkDns::ckCreate()
If dns.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; This gets all MX domains for an email address. (Typically one domain.)
; The preferred domain will be at index 0 (see below).
success = CkDns::ckQuery(dns,"MX",emailAddr,json)
If success = 0
Debug CkDns::ckLastErrorText(dns)
CkMailMan::ckDispose(mailman)
CkDns::ckDispose(dns)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(json,"answer.mx")
While i < count_i
CkJsonObject::setCkI(json, i)
domain = CkJsonObject::ckStringOf(json,"answer.mx[i].domain")
Debug domain
i = i + 1
Wend
CkMailMan::ckDispose(mailman)
CkDns::ckDispose(dns)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure