DnsAutodetectOptions Enumeration |
Namespace: MailBee.DnsMX
Member name | Value | Description | |
---|---|---|---|
None | 0 | Do nothing. | |
ConfigFiles | 1 | Search DNS server definitions in "MailBee.DnsMX.DnsServerCollection" key of "appSettings" section of the config files (such as app.config, web.config, or machine.config), where the key value contains ";"-separated list of DNS servers in "IP Address,Priority" format. If the priority is omitted, the top (0) priority will be assigned to the DNS server. If DnsServers is not empty, its entries are added too. | |
NetInterface | 2 | Uses System.Net.NetworkInformation.NetworkInterface class (requires UnmanagedCode permission). The most accurate method, however. | |
Registry | 4 | Search DNS server definitions in Windows registry. Usually, the last resort. Requires less permissions than NetInterface but less accurate. Supported in .NET Framework and .NET Standard 2.0 edition on Windows only. | |
Wmi | 8 | Search DNS server definitions in WMI database. Not supported in .NET Core 1.0/1.1 and UWP (not even in Windows 10 Fall Creators update). Supported in .NET Framework and .NET Standard 2.0 edition (but Full Trust is required, cannot be used by partially trusted code). | |
RootServers | 16 | Use DNS servers with addresses "8.8.8.8" and "8.8.4.4". These servers are always available but they belong to Google, not to your company or your ISP. They might not work well for some scenarios like DNS RBL checks. | |
AllowIPv6Servers | 32 | If set, IPv6 entries (if present) will appear in the list of autodetected servers. If not set, only IPv4 servers will be added. Has no effect for adding DnsServers (servers from there are added regardless of their type). |
If multiple methods are specified, they are tried in the order their values increase until at least one DNS server definition is found.
To search WMI database (Wmi option), the application must have appropriate permissions to use System.Management.dll (which encapsulates System.Management namespace). For instance, web applications configured to run on "High" trust level have no permissions to access this assembly. In this case, Autodetect method will not find any DNS server records in WMI database. Changing trust level to "Full" eliminates the problem.
To use System.Net.NetworkInformation.NetworkInterface class (the best method available), "High" trust level might also require "Full" level.
Note |
---|
DNS auto-detection may not work well on Xamarin (https://forums.xamarin.com/discussion/6386/how-to-get-the-dns-servers-ip-address), you may have to add DNS server manually with Add(String) method. You can also register them globally with DnsServers property (this will let Autodetect method succeed). |
Note |
---|
DNS autodetecton is limited in UWP platform. |
// To use the code below, import MailBee namespaces at the top of your code using MailBee; using MailBee.SmtpMail; using MailBee.DnsMX; // The actual code Smtp smtp = new Smtp(); smtp.DnsServers.Autodetect(DnsAutodetectOptions.ConfigFiles | DnsAutodetectOptions.Registry); // Example of XML config file settings which must be placed into <appSettings> section of the file // (<appSettings> can also appear as <applicationSettings> in .NET 2.0). // It defines 2 DNS servers with top (0) priority and 1 backup server with lower (1) priority // (for 192.168.0.2 server, the priority is not specified and thus defaults to the top priority): <add key="MailBee.DnsMX.DnsServerCollection" value="192.168.0.1,0;192.168.0.2;192.168.0.100,1"/>