使用OpenPop.NET删除邮箱中的信息。

问题描述 投票:3回答:2

我正在使用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.
    }
}
c# pop3
2个回答
5
投票

删除那些被标记的邮件。.DeleteMessage(messageNumber); 方法时,会发生 .Disconnect(); 方法被调用。


0
投票

如上所述,当连接关闭时,邮件就会被删除,另外,邮件编号应该以1开头,而不是以0开头。以gmail为例,你需要进入 "设置->转发POPIMAP->当邮件用POP访问时",选择 "删除gmail的副本"。

你可以查看 此处.

© www.soinside.com 2019 - 2024. All rights reserved.