Get email headers using POP3 (TOP command)

The POP3 protocol’s TOP command is useful to download only headers of the big email message, without actually downloading entire message including all attachments. With Mail.dll POP3 component it is easy to use TOP command, you simply invoke one of the GetHeadersBy method.

// C# version

using System;
using Limilabs.Mail;
using Limilabs.Client.POP3;

class Program
{
    static void Main(string[] args)
    {
        using (Pop3 pop3 = new Pop3())
        {
            pop3.Connect("pop3.example.com");    // or ConnectSSL
            pop3.Login("user", "password");

            MailBuilder builder = new MailBuilder();
            foreach (string uid in pop3.GetAll())
            {
                var headers = pop3.GetHeadersByUID(uid);
                IMail email = builder.CreateFromEml(headers);

                Console.WriteLine("subject: {0}", email.Subject);
            }
            pop3.Close();
        }
    }
}
' VB.NET version

Imports System
Imports Limilabs.Mail
Imports Limilabs.Client.POP3

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

        Using pop3 As New Pop3()
            pop3.Connect("pop3.example.com")    ' or ConnectSSL
            pop3.Login("user", "password")

            Dim builder As New MailBuilder()
            For Each uid As String In pop3.GetAll()
                Dim headers = pop3.GetHeadersByUID(uid)
                Dim email As IMail = builder.CreateFromEml(headers)

                Console.WriteLine("subject: {0}", email.Subject)
            Next
            pop3.Close()
        End Using

    End Sub
End Module

Tags:     

Questions?

Consider using our Q&A forum for asking questions.