private byte[] BytesFromString(string str)
{
return Encoding.ASCII.GetBytes(str);
}
private int GetResponseCode(string ResponseString)
{
return int.Parse(ResponseString.Substring(0, 3));
}
protected void Button1_Click(object sender, EventArgs e)
{
TcpClient tClient = new TcpClient("plus.smtp.mail.yahoo.com", 465);
string CRLF = "\r\n";
byte[] dataBuffer;
string ResponseString;
NetworkStream netStream = tClient.GetStream();
StreamReader reader = new StreamReader(netStream);
ResponseString = reader.ReadLine();
dataBuffer = BytesFromString("HELO " + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
dataBuffer = BytesFromString("MAIL FROM:<myemail@yahoo.com>" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
dataBuffer = BytesFromString("RCPT TO:<" + TextBox1.Text.Trim() + ">" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
ResponseString = reader.ReadLine();
if (GetResponseCode(ResponseString) == 550)
{
Response.Write("Mai Address Does not Exist !");
}
dataBuffer = BytesFromString("QUITE" + CRLF);
netStream.Write(dataBuffer, 0, dataBuffer.Length);
tClient.Close();
}
嗨,此代码不适用于 smtp yahoo 服务器,但代码适用于 gmail smtp 服务器 TcpClient tClient = new TcpClient("gmail-smtp-in.l.google.com", 25)
错误:已建立的连接被主机中的软件中止响应字符串 = reader.ReadLine();
并将端口服务器更改为 25 不会发生!smtp server 和 port server 是否有效?有没有办法确保电子邮件有效?有人可以帮助我吗?