【问题标题】:How to get the latest mail from hotmail account using TcpClient and SslStream如何使用 TcpClient 和 SslStream 从 hotmail 帐户获取最新邮件
【发布时间】:2012-05-02 09:45:59
【问题描述】:

我创建了一个 Windows 测试应用程序,我在其中连接到我的 hotmail 帐户并检查那里的未读邮件。目前通过我的应用程序,我正在从我的 hotmail 帐户获取最后一封邮件。

如何获取最新邮件以及是否可以使用 SSLStream 对象获取最新邮件的主题和正文。

我在这里发布我的代码。请帮助我。任何适当的帮助将不胜感激。写“获取第一封邮件”的地方,我只得到第一封邮件的总字节数.请帮我获取第一个电子邮件主题和正文。

        TcpClient mail = new TcpClient();
        SslStream sslStream;
        int bytes = -1;
        mail.Connect("pop3.live.com", 995);
        sslStream = new SslStream(mail.GetStream());
        sslStream.AuthenticateAsClient("pop3.live.com");

        byte[] buffer = new byte[2048];
        // Read the stream to make sure we are connected
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message);

        //Send the users login details
        sslStream.Write(Encoding.ASCII.GetBytes("USER user_name\r\n"));
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message1 = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message1);

        //Send the password                        
        sslStream.Write(Encoding.ASCII.GetBytes("PASS password\r\n"));
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message2 = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message2);

        // Get the first email 
        sslStream.Write(Encoding.ASCII.GetBytes("RETR 1\r\n"));
        bytes = sslStream.Read(buffer, 0, buffer.Length);
        string message4 = Encoding.ASCII.GetString(buffer, 0, bytes);
        MessageBox.Show(message4);

        string str = string.Empty;
        string strTemp = string.Empty;
        StreamReader reader = new StreamReader(sslStream); 
        while ((strTemp = reader.ReadLine()) != null)
        {

            // find the . character in line
            if (strTemp == ".")
            {
                break;

            }
            if (strTemp.IndexOf("-ERR") != -1)
            {
                break;

            }
            str += strTemp;

        }
        MessageBox.Show(str);
    }

通过对代码进行一些修改,我可以访问 hotmail 帐户。但是当我尝试访问 AOL 帐户时使用相同的代码。我收到 IO 异常。谁能帮助我如何连接到 AOL 邮件系统使用此代码。感谢您的帮助。

【问题讨论】:

    标签: c# windows tcpclient hotmail sslstream


    【解决方案1】:

    我认为你必须实现 pop 协议来获取 pop 服务器的电子邮件;在你的情况下,hotmail。您将找到有关通过herehere 从 pop3 服务器(如 hotmail/gmail)打开邮件的好文章

    【讨论】:

    • 你能详细说明一下吗,我对流行音乐不太了解
    • 我刚刚更新了我的答案。您可以在此处使用示例测试您的 hotmail 邮件检索,并了解如何完成它。 codeproject.com/Articles/261607/…
    • 我可以下载类库并在我的项目中使用它吗?那里可以下载。谢谢帮助我。请回复这个
    • 在给定页面上找到“下载源”或“下载演示”
    • 我复制了名为“pop3lib.dll”的 DLL,并将尝试使用 DLL 进行检查
    猜你喜欢
    • 2012-06-29
    • 2015-07-10
    • 1970-01-01
    • 2016-04-19
    • 2016-02-22
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多