public static List <MxRecord> MxQuery(string hostName, string nameServer) { UdpClient client = new UdpClient(nameServer, (int)Port.Dns); byte[] data = DNS.CreateQuery(hostName); IPEndPoint ip = null; client.Send(data, data.Length); data = client.Receive(ref ip); return(GetResponse(data, data.Length)); }
public static List <MxRecord> MxQuery(string hostName) { List <MxRecord> records; if (!_mxRecords.ContainsKey(hostName)) { records = DNS.MxQuery(hostName, DNS.NameServer); _mxRecords.Add(hostName, records[0]); } records = new List <MxRecord>(); records.Add(_mxRecords[hostName]); return(records); }
/// <summary> /// Validate an e-mail address by checking the mail server /// </summary> /// <param name="from"></param> /// <param name="recipient"></param> /// <returns></returns> public Stack <string> Ping(string from, string recipient) { if (!Regex.IsMatch(recipient, _pattern)) { _stack.Push(Result.BadAddressFormat.ToString()); return(_stack); } if (_port25blocked) { // execute through web service /*com.vasst.SMTP smtp = new com.vasst.SMTP(); * //Dim smtp As New com.webott.Utility * object[] response = smtp.Ping(recipient); * _stack.Clear(); * for (int x = response.Length - 1; x >= 0; x += -1) { * _stack.Push(response(x)); * } */ } else { // execute locally Result status = Result.Failed; string domain = this.HostPart(recipient); if (_testDomain) { try { IPHostEntry host = System.Net.Dns.GetHostEntry(domain); } catch { _stack.Push(Result.DomainNotResolved.ToString()); return(_stack); } } List <MxRecord> mxRecords = DNS.MxQuery(domain); if (mxRecords.Count == 0) { // if no records found then try common mail server name status = Result.NoMxRecords; mxRecords.Add(MxRecord.Infer(domain)); } else { mxRecords.Sort(); } for (int x = 0; x <= mxRecords.Count - 1; x++) { status = this.WillAccept(mxRecords[x].HostName, from, recipient); if (status.Contains(Result.MxComplete)) { break; } } _stack.Push(status.ToString()); } return(_stack); }