当试图从pop3c#访问邮件时,检索命令似乎不起作用
本文关键字:检索 命令 不起作用 pop3c# 访问 | 更新日期: 2023-09-27 18:15:30
当我连接到pop3.live.com时,连接很好,它还显示了我拥有的消息数量和文件大小,但是当我尝试使用"RETR"来获取消息并在控制台应用程序上显示它们时,什么也没有呈现。
这是我到目前为止写的
string str = string.Empty;
string strTemp = string.Empty;
using (TcpClient tc = new TcpClient())
{
tc.Connect("pop3.live.com", 995);
using (SslStream sl = new SslStream(tc.GetStream()))
{
sl.AuthenticateAsClient("pop3.live.com");
using (StreamReader sr = new StreamReader(sl))
{
using (StreamWriter sw = new StreamWriter(sl))
{
sw.WriteLine("USER " + _username);
sw.Flush();
sw.WriteLine("PASS "+ _password);
sw.Flush();
sw.WriteLine("LIST");
sw.Flush();
sw.WriteLine("RETR");
sw.Flush();
sw.WriteLine("QUIT ");
sw.Flush();
while ((strTemp = sr.ReadLine()) != null)
{
if (strTemp == "." || strTemp.IndexOf("-ERR") != -1)
{
break;
}
str += strTemp;
}
}
}
}
}
Console.WriteLine(str);
Console.ReadLine();
首先必须使用LIST命令,该命令列出消息编号。然后使用前面列表中的单个消息号发出一个或多个RETR命令。留言号码不一定从1开始!请参阅我对你关于调试这个问题的评论。
例如:LIST
+OK 2 messages (4095)
1 710
2 3385
.
RETR 1
+OK 710 octets
Return-Path: <john@example.com>
...
对于RETR
,您需要指定要检索的消息。根据POP3规范,不支持没有数字的RETR