Reputation: 1394
I am using OpenPop.NET client to get access to my mailbox via Pop3 protocol. All is fine, except one thing: I cannot delete messages. Even sample from official site doesn't help. I've tried it with several mail servers: gmail.com, yandex.ru, rambler.ru situation is the same.
Update - added code.
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.
}
}
Upvotes: 5
Views: 9674
Reputation: 125
As pointed above emails are deleted when the connection is closed, also the message number should start in one and not in zero. In the case of gmail you need to go to "settings->Forwarding POP/IMAP->When message accesed with POP" and select "delete gmail's copy".
You can check it here.
Upvotes: 1
Reputation: 3189
Deletion of the emails that are marked through the .DeleteMessage(messageNumber);
method happens when the .Disconnect();
method is called.
Upvotes: 6