0
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 是否有效?有没有办法确保电子邮件有效?有人可以帮助我吗?

4

1 回答 1

0

一些服务器机器用于响应从它的特定服务器获取数据而不是该机器无法响应的算法......

但是正如你所说的gmail提供数据,因此该机器不能对响应数据使用任何限制......

于 2013-07-31T09:07:57.287 回答