Returns the mail exchange servers for a given domain.
The MailExchange array returns the host name of the systems designated as the mail exchanges for the current domain. The mail exchange hosts are returned sorted in priority order, with the higher priority mail servers being listed first. The array is zero based, which means that the first index value is zero. The HostName property must be set to the domain name that you want to obtain the mail exchange records for.
This array is commonly used to determine which system is responsible for forwarding mail within a domain. For example, if
a mail message is addressed to the user someone@example.com, you can determine the name of the server or servers
responsible for accepting mail for that user by setting the value of the HostName property to example.com and
then checking the MailExchange array. Note that it is possible that a domain will not have any mail exchange
(MX) records, in which case you should attempt to connect directly to a mail server running on the host specified in the
domain name portion of the address.
The following example populates a ListBox control with the host names of those servers responsible for accepting email for the specified domain:
[Visual Basic]
Dim nIndex As Integer
ListBox1.Items.Clear()
dnsClient.HostName = strHostName
For nIndex = 0 To dnsClient.MailExchanges - 1
ListBox1.Items.Add(dnsClient.MailExchange(nIndex))
Next