我正在尝试测试我的 hotmail 帐户是否存在,但以下代码对我没有帮助。
public bool IsExists_SMTPMethod(string email)
{
string domain = email.Substring(email.IndexOf("@") + 1);
var servers = _commander.GetMXServers(domain);
Socket socket = null;
foreach (MXServer mxserver in servers)
{
IPHostEntry ipHost = Dns.Resolve(mxserver.MailExchanger);
IPEndPoint endPoint = new IPEndPoint(ipHost.AddressList[0], 25);
socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(endPoint);
if (!CheckResponse(socket, ResponseEnum.ConnectSuccess))
{
socket.Close();
}
else
{
// If connected, send SMTP commands
{
SendData(socket, string.Format("HELO {0}\r\n", "machinename"));
if (!CheckResponse(socket, ResponseEnum.GenericSuccess))
{
socket.Close();
continue;
}
SendData(socket, string.Format("MAIL FROM: <{0}>\r\n", "from@domain.com"));
CheckResponse(socket, ResponseEnum.GenericSuccess);
SendData(socket, string.Format("RCPT TO: <{0}>\r\n", email));
bool result = CheckResponse(socket, ResponseEnum.GenericSuccess);
if (!result)
{
socket.Close();
continue;
}
else
return true;
}
}
}
return false;
}