无法使用POP3删除电子邮件

时间:2016-10-11 22:01:35

标签: c# pop3

我的代码使用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,因此我看不出导致此失败的原因。

1 个答案:

答案 0 :(得分:1)

SendReceive()来电看错了。我的猜测是它应该在格式字符串中有一个{0}。换句话说,您的代码可能正在发送DELE而不是DELE 1

相关问题