Pop3 class provides two methods Delete for deleting messages and Undelete for undeleting messages.
You use the Delete method to mark a message as deleted. It won't appear in subsequent message lists, but will actually only be removed from the mailbox after the session is disconnected using Disconnect method. You can recover messages that were marked as deleted by using the Undelete method.
The following steps will help you to delete a single message using the Delete method:
Deleting a message
- Add using directives to your code to create aliases for existing namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:
using ComponentPro.Net;
using ComponentPro.Net.Mail;
Imports ComponentPro.Net
Imports ComponentPro.Net.Mail
- Create a new instance of the Pop3 class.
- Now you can connect to the POP3 server with Connect methods. The code looks similar to the following:
// POP3 server information.
const string serverName = "myserver";
const string user = "name@domain.com";
const string password = "mytestpassword";
const int port = 995;
const SslSecurityMode securityMode = SslSecurityMode.Implicit;
// Create a new instance of the Pop3 class.
Pop3 client = new Pop3();
// Connect to the server.
client.Connect(serverName, port, securityMode);
' POP3 server information.
Const serverName As String = "myserver"
Const user As String = "name@domain.com"
Const password As String = "mytestpassword"
Const port As Integer = 995
Const securityMode As SslSecurityMode = SslSecurityMode.Implicit
' Create a new instance of the Pop3 class.
Dim client As New Pop3()
' Connect to the server.
client.Connect(serverName, port, securityMode)
- Use your user name and password to login with Authenticate methods. The code looks similar to the following:
// Login to the server.
client.Authenticate(user, password);
' Delete a mail message with sequence number 1.
client.Delete(1)
- Now select a mailbox and pass the sequence number of the message to delete to the Delete method. The code looks similar to the following:
// Delete a mail message with sequence number 1.
client.Delete(1);
' Delete a mail message with sequence number 1.
client.Delete(1)
- After completing your work, call the Disconnect method to close the POP3 session.
Final example code
using ComponentPro.Net;
using ComponentPro.Net.Mail;
...
// POP3 server information.
const string serverName = "myserver";
const string user = "name@domain.com";
const string password = "mytestpassword";
const int port = 995;
const SslSecurityMode securityMode = SslSecurityMode.Implicit;
// Create a new instance of the Pop3 class.
Pop3 client = new Pop3();
// Connect to the server.
client.Connect(serverName, port, securityMode);
// Login to the server.
client.Authenticate(user, password);
// Delete a mail message with sequence number 1.
client.Delete(1);
// Close the connection.
client.Disconnect();
Imports ComponentPro.Net
Imports ComponentPro.Net.Mail
...
' POP3 server information.
Const serverName As String = "myserver"
Const user As String = "name@domain.com"
Const password As String = "mytestpassword"
Const port As Integer = 995
Const securityMode As SslSecurityMode = SslSecurityMode.Implicit
' Create a new instance of the Pop3 class.
Dim client As New Pop3()
' Connect to the server.
client.Connect(serverName, port, securityMode)
' Login to the server.
client.Authenticate(user, password)
' Delete a mail message with sequence number 1.
client.Delete(1)
' Close the connection.
client.Disconnect()