(Unicode C++) 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.
#include <CkDnsW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkDnsW dns;
CkJsonObjectW json;
const wchar_t *emailAddr = L"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).
success = dns.Query(L"MX",emailAddr,json);
if (success == false) {
wprintf(L"%s\n",dns.lastErrorText());
return;
}
int i = 0;
int count_i = json.SizeOfArray(L"answer.mx");
while (i < count_i) {
json.put_I(i);
const wchar_t *domain = json.stringOf(L"answer.mx[i].domain");
wprintf(L"%s\n",domain);
i = i + 1;
}
}
|