Я пытаюсь реализовать простой почтовый клиент. Теперь я могу retriev сообщения:Протокол POP3. Операции STAT и LIST
// create an instance of TcpClient
TcpClient tcpclient = new TcpClient();
// HOST NAME POP SERVER and gmail uses port number 995 for POP
tcpclient.Connect("pop.gmail.com", 995);
// This is Secure Stream // opened the connection between client and POP Server
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
// authenticate as client
sslstream.AuthenticateAsClient("pop.gmail.com");
//bool flag = sslstream.IsAuthenticated; // check flag
// Asssigned the writer to stream
StreamWriter sw = new StreamWriter(sslstream);
// Assigned reader to stream
StreamReader reader = new StreamReader(sslstream);
// refer POP rfc command, there very few around 6-9 command
sw.WriteLine("USER [email protected]");
// sent to server
sw.Flush();
sw.WriteLine("PASS my_pass");
sw.Flush();
// this will retrive your first email
sw.WriteLine("RETR 1");
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
// find the . character in line
if (strTemp == ".")
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
//str = reader.ReadToEnd();
// close the connection
sw.WriteLine("QUIT");
sw.Flush();
richTextBox2.Text = str;
Но когда я пытаюсь реализовать операции STAT
и LIST
моей программку аварии. Я думаю, что есть проблема в цикле чтения потоков. Для работы STAT
Я стараюсь читать до "\r\n"
(strTemp = "\r\n"
) и для эксплуатации LIST
- ".\r\n"
соответственно.
Это мой код для STAT
:
// create an instance of TcpClient
TcpClient tcpclient = new TcpClient();
// HOST NAME POP SERVER and gmail uses port number 995 for POP
tcpclient.Connect("pop.gmail.com", 995);
// This is Secure Stream // opened the connection between client and POP Server
System.Net.Security.SslStream sslstream = new SslStream(tcpclient.GetStream());
// authenticate as client
sslstream.AuthenticateAsClient("pop.gmail.com");
//bool flag = sslstream.IsAuthenticated; // check flag
// Asssigned the writer to stream
StreamWriter sw = new StreamWriter(sslstream);
// Assigned reader to stream
StreamReader reader = new StreamReader(sslstream);
// refer POP rfc command, there very few around 6-9 command
sw.WriteLine("USER [email protected]gmail.com");
// sent to server
sw.Flush();
sw.WriteLine("PASS my_pass");
sw.Flush();
// this will retrive your first email
sw.WriteLine("STAT");
sw.Flush();
string str = string.Empty;
string strTemp = string.Empty;
while ((strTemp = reader.ReadLine()) != null)
{
// find the . character in line
if (strTemp == "\r\n")
{
break;
}
if (strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
//str = reader.ReadToEnd();
// close the connection
sw.WriteLine("QUIT");
sw.Flush();
richTextBox2.Text = str;
После нажатия кнопки мое главное окно не отвечает. Где моя ошибка?
Спасибо!
Любая действительная причина, по которой вы игнорируете существующие библиотеки, например. [OpenPOP] (http://hpop.sourceforge.net)? –
Что такое исключение «сбоя» (поскольку это CLR, там нет GPF, есть)? Какой код вы добавили, чтобы вызвать его? Здесь не так много телепатов, вы знаете. –
@ivan_pozdeev, я редактировал мой вопрос. Это задача для моей лаборатории, поэтому я не могу импортировать библиотеки в свой проект. Я сделал это в соответствии со спецификациями и не могу понять, почему он не работает. Есть идеи? – user3443227