Finding the MX Record using C#?

后端 未结 3 907
一向
一向 2020-12-16 05:04

How can I find the MX record for a mail server in C#?

相关标签:
3条回答
  • 2020-12-16 05:16

    Take a look at this DNS resolver project on codeproject.com. The library has a Resolver class that contains a method named Query which can be used to go after the MX record.

    0 讨论(0)
  • 2020-12-16 05:17

    You can use the answer of Robert and RPK to get the MX record of a given domain.

    But you'll need a DNS server to do the job. If you want to detect the DNS server of the machine where your code is executed, you can use the following.

    NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface adapter in adapters)
    {
        IPInterfaceProperties properties = adapter.GetIPProperties();
    
        if (properties.DnsAddresses.Count > 0)
            foreach (IPAddress ipAddress in properties.DnsAddresses)
                 dnsServers.Add(ipAddress.ToString(), 53);
    }
    

    There is a complete solution (or at github here) that will do the whole job if you don't want to rewrite everything. Look for GetMxRecords static method.

    0 讨论(0)
  • 2020-12-16 05:30

    The NMail project contains a DNS client under trunk/NMail.DnsClient. The project is available under the Apache license.

    0 讨论(0)
提交回复
热议问题