4

我正在使用 OpenPop.NET 客户端通过 Pop3 协议访问我的邮箱。一切都很好,除了一件事:我无法删除消息。即使来自官方网站的样本也无济于事。我用几个邮件服务器尝试过:gmail.com、yandex.ru、rambler.ru 情况是一样的。

更新 - 添加代码。

static void Main(string[] args)
{
    DeleteMessageOnServer("pop.gmail.com", 995, true, USERNAME, PASSWORD, 1);
}

public static void
    DeleteMessageOnServer(string hostname, int port, bool useSsl, string username,
    string password, int messageNumber)
{
    // The client disconnects from the server when being disposed
    using (Pop3Client client = new Pop3Client())
    {
        // Connect to the server
        client.Connect(hostname, port, useSsl);

        // Authenticate ourselves towards the server
        client.Authenticate(username, password);

        // Mark the message as deleted
        // Notice that it is only MARKED as deleted
        // POP3 requires you to "commit" the changes
        // which is done by sending a QUIT command to the server
        // You can also reset all marked messages, by sending a RSET command.
        client.DeleteMessage(messageNumber);

        // When a QUIT command is sent to the server, the connection between them are closed.
        // When the client is disposed, the QUIT command will be sent to the server
        // just as if you had called the Disconnect method yourself.
    }
}
4

2 回答 2

5

调用该方法时会删除通过该.DeleteMessage(messageNumber);方法标记的电子邮件.Disconnect();

于 2012-11-02T02:33:13.697 回答
1

如上所述,当连接关闭时,电子邮件会被删除,消息编号也应该从 1 开始,而不是从 0 开始。如果是 gmail,您需要转到“设置->转发 POP/IMAP->当消息加入 POP 时”并选择“删除 gmail 的副本”。

你可以在这里查看

于 2020-05-13T22:22:52.560 回答