0

我正在尝试从电子邮件箱中读取电子邮件并在特定条件下删除其中一些。出于这个原因,我正在使用开放式流行库。当我尝试迭代和删除电子邮件时,我收到以下错误:'无法访问已处理的 OpenPop.Pop3.Pop3Client。对象名称:'OpenPop.Pop3.Pop3Client'。'

Pop3Client popClient = new Pop3Client();

popClient.Connect("mail.test.com", 110, false);
popClient.Authenticate("test.com", "testpass");

int messageCount = popClient.GetMessageCount();

List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);

for (int i = messageCount; i > 0; i--)
{
    allMessages.Add(popClient.GetMessage(i));
}

for(int i = allMessages.Count() - 1; i > 0; i--)
{
    StringBuilder builder = new StringBuilder();

    OpenPop.Mime.MessagePart plainText = allMessages[i].FindFirstPlainTextVersion();

    if (plainText != null)
    {
        builder.Append(plainText.GetBodyAsText());
        string emailText = builder.ToString();
        string email = GetStringValue("Email Address: ", emailText).Trim();
    }

    if (email != "test@gmail.com)
    {
        popClient.DeleteMessage(i);
        popClient.Disconnect();           
    }

}
4

0 回答 0