我创建了一个 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 邮件系统。谢谢你的帮助。