public static string[] GetMXRecords(string domain) { IntPtr ptr1 = IntPtr.Zero; IntPtr ptr2 = IntPtr.Zero; MXRecord recMx; if (Environment.OSVersion.Platform != PlatformID.Win32NT) { throw new NotSupportedException(); } ArrayList list1 = new ArrayList(); int num1 = MxLookupHandler.DnsQuery(ref domain, QueryTypes.DNS_TYPE_MX, QueryOptions.DNS_QUERY_BYPASS_CACHE, 0, ref ptr1, 0); if (num1 != 0) { throw new Win32Exception(num1); } for (ptr2 = ptr1; !ptr2.Equals(IntPtr.Zero); ptr2 = recMx.pNext) { recMx = (MXRecord)Marshal.PtrToStructure(ptr2, typeof(MXRecord)); if (recMx.wType == 15) { string text1 = Marshal.PtrToStringAuto(recMx.pNameExchange); list1.Add(text1); } } MxLookupHandler.DnsRecordListFree(ptr2, 0); return((string[])list1.ToArray(typeof(string))); }
private static MechanismResponse GetAutoconfigByDomain(string domain, RequestType requestType) { MechanismResponse returnVal = new MechanismResponse(); if (!string.IsNullOrEmpty(domain)) { List <Mechanism> mechanisms = GetMechanisms(); switch (requestType) { case RequestType.Standard: returnVal = AttemptAll(mechanisms, domain); break; case RequestType.MxLookup: bool found = false; string[] mxRecords = MxLookupHandler.GetMXRecordsTrimDistinct(domain); if (mxRecords != null && mxRecords.Length > 0) { foreach (string mx in mxRecords) { returnVal = AttemptAll(mechanisms, mx); found = returnVal != null && returnVal.IsSuccess; if (found) { break; } } if (!found) //Guess from the mx record { foreach (string mx in mxRecords) { returnVal = MxGuessHandler.GuessConfig(mx); found = returnVal != null && returnVal.IsSuccess; if (found) { break; } } } } break; case RequestType.Guess: returnVal = MxGuessHandler.GuessConfig(domain); break; } } if (returnVal != null) { returnVal.RequestType = requestType; } return(returnVal); }