# DNS lookup for MX record

**URL:** <https://clarionhub.com/t/dns-lookup-for-mx-record/7648>\
**Category:** questions\
**Tags:** nettalk, network, email\
**Created:** [November 6, 2024, 3:19pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648 "2024-11-06T15:19:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [November 6, 2024, 3:19pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/1 "2024-11-06T15:19:17Z")

</div>

I thought NetTalks new NetDNS was used for DNS lookups, but it seems to be a client for DNS registrars instead - is there any recommended way to query a domain name for it's MX record?

Reference NetTalk: [NetTalk DNS](https://www.capesoft.com/docs/NetTalk14/NetTalkDNS.htm)

---

<div class="post-metadata">

**Author:** ![lodestar](https://clarionhub.com/user_avatar/clarionhub.com/lodestar/32/1055_2.png) [@lodestar](https://clarionhub.com/u/lodestar)\
**Post date:** [November 6, 2024, 4:41pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/2 "2024-11-06T16:41:53Z")

</div>

> **[DnsQuery\_A function (windns.h) - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/api/windns/nf-windns-dnsquery_a)**
>
> Is the generic query interface to the DNS namespace, and provides application developers with a DNS query resolution interface. (DnsQuery\_A)

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [November 7, 2024, 8:53am UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/3 "2024-11-07T08:53:11Z")

</div>

Thanks, but how do I implement this in Clarion?  
I’ve found the following but it’s a bit hard to follow:

> [@Email validation using MATCH (RegEx)](https://clarionhub.com/t/email-validation-using-match-regex/1992/26):
>
> 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(…

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [November 7, 2024, 1:25pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/4 "2024-11-07T13:25:46Z")

</div>

[Dnsapi.zip](https://clarionhub.com/uploads/short-url/bg2rrHAjf3FE1mKHkFXTz5EdsAo.zip) (1,9 KB)

I’ve got it working with the above implementation - the lib refers to the `Dnsapi.dll` in the `Windows\System32` folder which contains the required functions.

Add the contents of the zip to your project, simply include the `.inc` file in the global includes and then create an instance of `Win32DNS` class and use the `Lookup` of one of it’s version to do a DNS call

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [November 7, 2024, 2:12pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/5 "2024-11-07T14:12:05Z")

</div>

Hi Dylan - Looks like a cool solution.

FWIW, on line 36, you have this:

```clarion
        searchName = LEFT(CLIP(host));

```

it should read as

```clarion
        searchName = CLIP(LEFT(host));

```

Otherwise, you would end up with trailing spaces if there were, in fact, space(s) passed in front of the host name. e.g. " [hostname.com](http://hostname.com)" would become "[hostname.com](http://hostname.com) "

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [November 7, 2024, 2:36pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/6 "2024-11-07T14:36:15Z")

</div>

Oh thank you - I came across that combination here in the forums - thanks for the headsup - I am not at my laptop so can’t quickly change the zip contents

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [November 7, 2024, 4:18pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/7 "2024-11-07T16:18:24Z")

</div>

A git repo or gist would be cool too.

---

<div class="post-metadata">

**Author:** ![ThaDaSoft](https://clarionhub.com/user_avatar/clarionhub.com/thadasoft/32/3743_2.png) [@ThaDaSoft](https://clarionhub.com/u/ThaDaSoft)\
**Post date:** [November 7, 2024, 5:38pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/8 "2024-11-07T17:38:46Z")

</div>

@jslarve of what? I shared the code - except a fully working app that is

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [November 7, 2024, 6:22pm UTC](https://clarionhub.com/t/dns-lookup-for-mx-record/7648/9 "2024-11-07T18:22:50Z")

</div>

What’s nice about using a gist or repo is that you still have control over the original, and just post updates to it (such as fixing bugs or adding features).

For example, here’s one of Carl’s gists. You can see that there are 7 revisions, etc. You can add multiple files to a gist.

> <https://gist.github.com/CarlTBarnes/29f78a2ca43813e83489dc62a4d5e0c0>
>
> There are more than three files. show original
