Retrieves the list of hosts willing to accept mail for the given domain.
The array of string names of hosts willing to accept mail for the given domain, or LocalSmtpMXServerName if domain is an empty string, or a null reference (Nothing in Visual Basic) if an error occurred.
This methods makes DNS MX query to the servers listed in DnsServers collection regarding domain. The method will return host the domain name itself if the DNS query reports the given domain contains A record only (i.e. the given domain is willing to accept mail for itself). MX records are returned accordingly their priorities (higher priority listed first).
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | domain is a null reference (Nothing in Visual Basic). |
| MailBeeException | An error occurred and ThrowExceptions is true. |
This sample retrieves the list of DNS MX server names accepting mail for "hotmail.com" domain.
[C#] using System; using MailBee; using MailBee.SmtpMail; class Sample { static void Main(string[] args) { Smtp mailer = new Smtp(); mailer.DnsServers.Autodetect(); string[] hosts = mailer.GetMXHosts("hotmail.com"); foreach (string host in hosts) { Console.WriteLine(host); } } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Class Sample Shared Sub Main(ByVal args() As String) Dim mailer As Smtp = New Smtp mailer.DnsServers.Autodetect() Dim hosts() As String = mailer.GetMXHosts("hotmail.com") Dim host As String For Each host In hosts Console.WriteLine(host) Next End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace