Delete emails with POP3

This article describes how to delete email messages using Mail.dll .NET POP3 component and POP3 protocol.

Internally deleted messages are only marked for deletion. Email messages are actually deleted by POP3 server after the client issues successful QUIT command – in other words: when client disconnects.

Following code will find unique ids of all messages and delete them one by one.

// C# version

using Limilabs.Client.POP3;

class Program
    static void Main(string[] args)
        using (Pop3 pop3 = new Pop3())
            pop3.Connect("");    // use ConnectSSL for SSL.
            pop3.Login("user", "password");

            // Delete all messages
            foreach (string uid in pop3.GetAll())

' VB.NET version

Imports Limilabs.Client.POP3

Public Module Module1
    Public Sub Main(ByVal args As String())

        Using pop3 As New Pop3()
            pop3.Connect("")  ' use ConnectSSL for SSL.
            pop3.Login("user", "password")

            ' Delete all messages
            For Each uid As String In pop3.GetAll()

        End Using

    End Sub
End Module

Here you can find Gmail POP3 behavior regarding downloading and deleting email messages.

Tags: , , ,

4 Responses to “Delete emails with POP3”

  1. Peter Steiness Says:

    Hello Limilabs

    On some servers, the method “pop3.DeleteMessageByUID (uid);” does not work.
    There are no error messages, but nothing happens, the mail is still there.

    What can be causing this problem?

    Peter Steiness

  2. Limilabs support Says:

    @Peter Steiness

    Remember to use Close method, as DeleteMessageByUID only marks message for deletion. Message is actually deleted after successful close command is received by the server.

    Some servers behave differently than the standard describes. For example Gmail:

  3. cezar alejandro Says:

    This is my code:

    pop3.Connect("") ' use ConnectSSL for SSL.

    whenever I try to connect says “An error occurred during the connection attempt because the connected party did not properly respond after a period of time, or there was an error in the connection established because connected host has failed to respond”

  4. Limilabs support Says:


    You must use SSL when connecting to Hotmail servers:



Consider using our Q&A forum for asking any questions.