/// <summary> /// Resolve Mx address /// </summary> /// <param name="a_host">Host</param> /// <returns>List of Mx address</returns> public Tuple <IList <string>, string> Resolve(string a_host) { IList <string> results = new List <string>(); DnsClient.MXHost[] mxCollection; try { mxCollection = DnsClient.LookupMX(a_host); } catch (Exception exception) { return(new Tuple <IList <string>, string>(results, exception.ToString())); } foreach (var row in mxCollection.OrderBy(a_c => a_c.Preference)) { if (row.IPAddresses != null) { foreach (IPAddress ipAddress in row.IPAddresses) { results.Add(ipAddress.ToString()); } } } return(new Tuple <IList <string>, string>(results, string.Empty)); }
public static bool IsMxSettedUpCorrectForDomain(string domain_name, string mx_record, ILogger logger = null) { try { var domain_mx_records = DnsClient.LookupMX(domain_name); if (domain_mx_records == null) { throw new ArgumentException("MX record on your domain is missing."); } return(domain_mx_records.Any(re => re.HostName == mx_record)); } catch (Exception ex) { if (logger != null) { logger.Debug("DnsClient.LookupMX: domain: '{0}' mx: '{1}'\r\nException: {2}", domain_name, mx_record, ex.ToString()); } return(false); } }