我有使用 POP3 访问电子邮件帐户并搜索已发送但地址不存在的邮件的代码。处理完它们后,我删除了失败消息。我有一个客户可以获取和处理消息,但无法删除它们。他们不断收到消息 Error deleting message 1: -ERR The specified message is out of range.
我的删除方法的代码如下。这适用于大多数客户端,而且非常简单,所以我不确定为什么它不起作用。
public bool Delete(int index)
{
bool result = false;
String response = SendReceive("DELE ", index.ToString());
if (response.StartsWith("+OK"))
result = true;
else
logger.Log("Error deleting message " + index + ": " + response, Verbose.LogImportant);
return result;
}
对于 SendReceive 方法:
private String SendReceive(String command, String parameter)
{
String result = null;
try
{
String myCommand = command.ToUpper().Trim() + " " + parameter.Trim() + Environment.NewLine;
byte[] data = System.Text.Encoding.ASCII.GetBytes(myCommand.ToCharArray());
tcpClient.GetStream().Write(data, 0, data.Length);
result = streamReader.ReadLine();
}
catch { } // Not logged in...
return result;
}
索引直接取自收到的电子邮件,直到删除方法处理完毕后连接才会关闭。由于必须返回一封电子邮件才能运行此方法,并且由于索引从 1 运行到 n,并且发送了 1,所以我看不出是什么导致此方法失败。
最佳答案
SendReceive()
调用看起来不对。我的猜测是它可能在格式字符串中有一个 {0}
。换句话说,您的代码可能正在发送 DELE
而不是 DELE 1
。
关于c# - 无法使用 POP3 删除电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39987482/