我正在尝试检查是否存在电子邮件地址。我可以针对SMTP服务器@gmail.com
验证gmail-smtp-in.l.google.com
地址,但我不知道如何获取其他域的SMTP服务器,以进行检查。请告知如何获取域的SMTP服务器,或者另外一种方法来可靠地检查是否存在电子邮件地址。
这是我检查@gmail.com
地址的代码:
TcpClient tClient = new TcpClient("gmail-smtp-in.l.google.com", 25);'
string CRLF = "\r\n";
byte[] dataBuffer;
string ResponseString;
NetworkStream netStream = tClient.GetStream();
StreamReader reader = new StreamReader(netStream);
ResponseString = reader.ReadLine();
/* Perform HELO to SMTP Server and get Response */
dataBuffer = BytesFromString("HELO AnkurHere" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
dataBuffer = BytesFromString("MAIL FROM:<abc@gmail.com>" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
/* Read Response of the RCPT TO Message to know from google if it exist or not */
dataBuffer = BytesFromString("RCPT TO:<" + TextBox1.Text.Trim() + ">" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
if (GetResponseCode(ResponseString) == 550)
{
label1.Text = "Mai Address Does not Exist !";
label2.Text = "Original Error from Smtp Server" + ResponseString;
}
/* QUITE CONNECTION */
dataBuffer = BytesFromString("QUITE" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
tClient.Close();
答案 0 :(得分:0)
对于您正在制作的方法,您需要对域的MX记录进行DNS查找。据我所知,.NET中没有内置方法可以做到这一点,所以你要么必须找到一个组件,要么看看this question。
但是,您需要被告知此方法不会给出100%准确的结果并且可能会产生误报 - 某些域将接受任何地址的消息,然后将其放入“全部捕获”邮箱,静默删除它或发送退回邮件。接受弹跳并不是最佳做法,但有时仍会发生。