Deleting Messages from POP3 Server

Aspose.Email is a robust component that allows performing customized operations after certain actions. Aspose.Email supports many events upon which users can perform operations. This feature provides users more control over their application. For example, users can perform their desired actions when:

  • All bulk emails have been sent.
  • A message is about to be sent.
  • An email is completely sent.
  • When a recipient is rejected by the SMTP server.

POP3 mailboxes reside on a POP3 server. The email in these mailboxes can be retrieved to your PC by Pop3Client. The Pop3Client class uses POP3 protocol to copy the mail messages from your POP3 mailbox to your PC. Once the mail has been retrieved you do not need to be connected to the internet while it is being read as you could read the retrieved mail on your PC. If you don’t need or want a copy of some mail messages kept on the POP3 server, you then delete it. This section shows how to delete emails using Pop3Client class.

Delete an Email by Index

The following code snippet deletes all the mail messages of a mailbox one by one, based on its index. Index should never be <=0 in Pop3Client.DeleteMessage.

Delete All Emails

We might also call Pop3Client.DeleteMessages to delete all the messages. The following code snippet shows you how to delete all emails.

// Delete all the messages
client.DeleteMessages();

If the connection to the POP3 server is broken immediately after deleting operations, you can no longer call Cancel Deletes to do the things you want.

Cancel Deletes

Pop3Client.UndeleteMessages can be used to cancel the deletion of email messages. The following code snippet shows you how to cancel deletes.

// Cancel deletes
client.UndeleteMessages();