本文介绍了查找MX记录使用C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何才能找到在C#中的邮件服务器的MX记录?

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

推荐答案

您可以使用罗伯特和的获得给定域的MX记录。

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

但是,你需要一个DNS服务器来完成这项工作。如果你想在那里执行你的代码来检测本机的DNS服务器,可以使用下面的。

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);
}

有一个的如果你不想改写一切,会做整个工作。查找 GetMxRecords 静态方法。

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

这篇关于查找MX记录使用C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 17:13