Dart.PowerTCP.SslSockets Namespace > Dns Class : BeginGetMailHosts Method |
Asynchronously get the mail server (or servers) responsible for receiving mail for a given email address.
[Visual Basic]
<DescriptionAttribute("Begin an asynchronous mail address/host to IP address resolution.")>
Public Function BeginGetMailHosts( _
ByVal mailAddress As String, _
ByVal state As Object _
) As IAsyncResult
[C#]
[DescriptionAttribute("Begin an asynchronous mail address/host to IP address resolution.")]
public IAsyncResult BeginGetMailHosts(
string mailAddress,
object state
);
[C++]
[DescriptionAttribute("Begin an asynchronous mail address/host to IP address resolution.")]
public: IAsyncResult* BeginGetMailHosts(
string* mailAddress,
Object* state
)
[C++/CLI]
[DescriptionAttribute("Begin an asynchronous mail address/host to IP address resolution.")]
public:
IAsyncResult^ BeginGetMailHosts(
String^ mailAddress,
Object^ state
)
An IAsyncResult that represents the asynchronous operation, which could still be pending.
Exception | Description |
---|---|
SocketException | No DNS server was specified. |
InvalidOperationException | BeginXXX method used without providing an EndXXX event handler. |
This method asynchronously gets the mail server for the provided domain or email address. When the lookup completes, the EndGetMailHosts event is raised. Made available in this event is a DnsEventArgs which describes the response from the DNS server. 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 GetMailHosts method may return an empty collection. This could mean one of the following:
To resolve a host name or a dot address asynchronously, use BeginGetHost. To resolve an email address synchronously, use GetMailHosts.
The following example demonstrates asynchronously resolving an email address.
[Visual Basic]
Private Sub AsynchResolveTest()
Dns1.Server = "206.64.128.5"
Dns1.BeginGetMailHosts("gates@microsoft.com", Nothing)
End Sub
Private Sub Dns1_EndGetMailHosts(ByVal sender As Object, ByVal e As DnsEventArgs) Handles Dns1.EndGetMailHosts
' Check for any exceptions that occurred
If e.Exception Is Nothing Then
' Iterate through all IPHostEntry objects
Dim result As System.Net.IPHostEntry
For Each result In e.Hosts
DisplayResult(result)
Next
End If
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 AsynchResolveTest()
{
dns1.Server = "206.64.128.5";
dns1.BeginGetMailHosts("gates@microsoft.com", null);
}
private void dns1_EndGetMailHosts(object
sender, DnsEventArgs e)
{
// Check for any exceptions that occurred
if(e.Exception == null)
{
// Iterate through all IPHostEntry objects
foreach(System.Net.IPHostEntry result in
e.Hosts)
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 Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.