Hello Rudik …
Here is a sample showing how I query an MX record, extract whatever you need to make it your own. It is very quick taking no longer than any other DNS query.
I use a .dll loader class so don’t prototype many procedures but you could use these:
DnsQuery_A(
lpszName LONG,
wType SHORT,
options SHORT,
lpExtra LONG,
lpResults LONG,
lpReserved LONG
),LONG,PASCAL,Name(‘DnsQuery_A’)
DnsRecordListFree(LONG p,LONG t),PASCAL,name(‘DnsRecordListFree’)
Other prototypes …
memcpy(Long lpDestination,Long lpSource,Long dwLen),Long,Proc,Name(’_memcpy’)
strcpy(Long destination,Long Source),Name(’_strcpy’)
jhDNScl_Type.QueryMX Procedure(STRING inDomain)
!-- Defined in the .inc file
!jhDNS:Benign EQUATE(0)
!jhDNS:Invalid EQUATE(1)
!jhDNS:Valid EQUATE(2)
procName EQUATE(‘QueryMX’)
DNS_QUERY_STANDARD EQUATE(0)
DNS_Type_MX EQUATE(0FH)
dwResult LONG,AUTO
dwReturn LONG
lpData LONG ! Pointer to the resulting data … a DNS Record structure
szName CSTRING(128),AUTO
MXRecord GROUP
lpNext LONG
lpszName LONG ! LPCSTR
wType Short
wDataLength Short
dwFlags LONG
dwTtl LONG
dwReserved Long
lpszNameExchange LONG ! LPCSTR
wPreference Short
Pad Short
.
Code
!-- Clear the MXRecord structure initially …
CLEAR(MXRecord)
!-- Transfer the domain name into a CSTRING ..
szName = CLIP(Lower(inDomain))
!-- Make the call ..
dwResult = SELF.myDLL.call('DnsQuery_A',Address(szName),DNS_TYPE_MX,DNS_QUERY_STANDARD,0,Address(lpData),0)
CASE dwResult
of 0
!-- Successful call to DnsQuery_A
if lpData
!-- Copy the MXData pointed to by lpData
memcpy(Address(MXRecord),lpData,SIZE(MXRecord))
!-- lpszNameExchange points to an Mail Exchange Server ..
strcpy(Address(szName),MXRecord.lpszNameExchange)
!-- Free the internal memory allocated by DnsQuery_A ..
dwResult = SELF.myDLL.call('DnsRecordListFree',lpData,1)
!-- and set dwSuccess = True
dwReturn = jhDNS:Valid
ELSE
!-- set dwSuccess indicating not found
dwReturn = jhDNS:Invalid
.
of 9003
!-- Name does not exist
dwReturn = jhDNS:Invalid
ELSE
! MESSAGE('DNS MX Query: ’ & inDomain & |
! '||Query dwResult = ’ & dwResult )
!-- Some other unknown ..
dwReturn = jhDNS:Benign
.
RETURN(dwReturn)
I agree with Simon’s comment not to enter into SMTP engagement outside the actual send attempt and this method doesn’t tell you whether an actual email address exists nor does it indicate whether the catchall is active.
I periodically query all target domains saving the query date & result: pass/fail that way I can eliminate emails that I know in advance are going to bounce.
Julian