Dart.PowerTCP.EmailValidation Namespace > Dns Class : GetMailHosts Method |
Get the mail server (or servers) responsible for receiving mail for a given email address.
[Visual Basic]
<DescriptionAttribute("Perform a synchronous mail address/host to address resolution.")>
Public Function GetMailHosts( _
ByVal mailAddress As String _
) As IPHostEntry()
[C#]
[DescriptionAttribute("Perform a synchronous mail address/host to address resolution.")]
public IPHostEntry[] GetMailHosts(
string mailAddress
);
[C++]
[DescriptionAttribute("Perform a synchronous mail address/host to address resolution.")]
public: IPHostEntry*[]* GetMailHosts(
string* mailAddress
)
[C++/CLI]
[DescriptionAttribute("Perform a synchronous mail address/host to address resolution.")]
public:
array<IPHostEntry^>^ GetMailHosts(
String^ mailAddress
)
An array of System.Net.IPHostEntry object representing the mail server(s) responsible for receiving mail for a given email address.
Exception | Description |
---|---|
SocketException | No DNS server was specified. |
This method returns the mail server for the provided domain or email address. The result of the query may include multiple mail servers. If more than one is found, the most preferred server is first in the list and the least preferred is at the end of the list.
The Dns.GetMailHosts method may return an empty collection. This could mean one of the following:
To resolve a host name or a dot address, use Dns.GetHost. To resolve an email address asynchronously, use Dns.BeginGetMailHosts.
The following example demonstrates resolving an email address.
[Visual Basic]
Private Sub ResolveTest()
Dns1.Server = "206.64.128.5"
Dim results = Dns1.GetMailHosts("gates@microsoft.com")
'Iterate through all IPHostEntry objects
Dim result As System.Net.IPHostEntry
For Each result In results
DisplayResult(result)
Next
End Sub
Private Sub DisplayResult(ByVal result As System.Net.IPHostEntry)
' Display host name
Debug.WriteLine("Host name: " + result.HostName)
' Display addresses, if any
Dim add As System.Net.IPAddress
For Each add In result.AddressList
Debug.WriteLine("Address: " + add.ToString())
Next
' Display aliases, if any
Dim s As String
For Each s In result.Aliases
Debug.WriteLine("Aliases: " + s)
Next
End Sub
[C#]
private void ResolveTest()
{
dns1.Server = "206.64.128.5";
System.Net.IPHostEntry[] results = dns1.GetMailHosts("gates@microsoft.com");
// Iterate through all IPHostEntry objects
foreach(System.Net.IPHostEntry result in results)
DisplayResult(result);
}
private void DisplayResult(System.Net.IPHostEntry result)
{
// Display host name
Debug.WriteLine("Host name: " + result.HostName);
// Display addresses, if any
foreach(System.Net.IPAddress add in result.AddressList)
Debug.WriteLine("Address: " + add.ToString());
// Display aliases, if any
foreach(string s in result.Aliases)
Debug.WriteLine("Aliases: " + s);
}
Platforms: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP, Windows Server 2003, Windows Vista
Send comments on this topic.
Documentation version 1.0.3.0.
© 2008 Dart Communications. All rights reserved.