Finding the MX Record using C#?

2019-01-23 20:16发布

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

6条回答
Anthone
2楼-- · 2019-01-23 20:21
▲ chillily
3楼-- · 2019-01-23 20:29

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.

查看更多
我只想做你的唯一
4楼-- · 2019-01-23 20:36

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 that will do the whole job if you don't want to rewrite everything. Look for GetMxRecords static method.

查看更多
Rolldiameter
5楼-- · 2019-01-23 20:36

I just wrote a simple asp.net generic handler to do the job of finding the mx records which you can use to code an Windows App.

Generic Handler to find MX Records

查看更多
该账号已被封号
6楼-- · 2019-01-23 20:36

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

查看更多
登录 后发表回答