DnsEnumMailExchanges Function  
 
INT WINAPI DnsEnumMailExchanges(
  HCLIENT hClient,  
  LPCTSTR lpszHostName,  
  LPTSTR *lpszMailExchanges,  
  INT nMaxMailExchanges  
);

The DnsEnumMailExchanges function returns a list of mail exchanges for the specified host name or IP address.

Parameters

hClient
Handle to the client session.
lpszHostName
Pointer to the string that contains the hostname or domain name to be queried.
lpszMailExchanges
Pointer to an array of string pointers which specify one or more mail exchanges. If the application needs to store these values, a local copy should be made because they are invalidated when another host name is resolved. The list of mail exchange records is sorted in priority order, from highest (i.e., those whose preference value is smallest) to lowest.
nMaxMailExchanges
The maximum number of mail exchanges in the array. If this parameter is 0, then the function will return the number of mail exchanges, but the list of mail exchanges will not be output in lpszMailExchanges.

Return Value

If the function succeeds, the return value is the number of mail exchanges. If the function fails, the return value is DNS_ERROR. To get extended error information, call DnsGetLastError.

Example

// Count the number of mail exchanges
if ((nMX = DnsEnumMailExchanges(hClient,szHostName, NULL, 0)) == DNS_ERROR)
{
    dwError = DnsGetLastError();
    DnsGetErrorString(dwError, szError, BUFSIZE);
    printf("DnsEnumMailExchanges failed for %s: %s\n", szHostName, szError);
}
else
{
    int nIndex;
    printf("%d MX for %s\n",nMX, szHostName);

    // Allocate memory for the list of mail exchanges
    lpszMailExchanges = (LPTSTR *)malloc(nMX * sizeof(LPTSTR));

    // Retrieve the list of mail exchanges
    nMX = DnsEnumMailExchanges(hClient, szHostName, lpszMailExchanges, nMX);

    for (nIndex = 0; nIndex < nMX; nIndex++)
         printf("#%d: %s\n", nIndex+1, *lpszMailExchanges++);

    free(lpszMailExchanges);
}

Requirements

Client: Requires Windows 7, Windows Vista or Windows XP.
Server: Requires Windows Server 2008 or Windows Server 2003.
Header: Include cstools7.h.
Library: Use csdnsav7.lib.
Unicode: Implemented as Unicode and ANSI versions.

See Also

DnsGetMailExchange