Ferrysoft POP3 Module

POP3 Module

Overview

The Ferrysoft POP3 Module is a Post Office Protocol (POP3) client class to interrogate a POP3 server for available emails, download the emails and return them to the calling program. The POP3 Module is provided in source code form (Visual Basic 2005/2008 compatible and Visual C# 2005/2008 compatible). It is intended for developers, to incorporate into their own applications, in order to provide POP3 client support to the application. The module can be used, royalty-free, by any individual or organisation that purchases the module. As the module is provided in source code form, it can be modified as necessary after purchase, provided that any derived module is not distributed, in source code form, to a third party. The module can be incorporated into a commercial product and sold to third parties, in compiled format, provided that the purpose of the commercial product is not simply to act as a wrapper for the POP3 Module.

Buy It

The POP3 Module is available for download in a password protected zip file. A royalty-free source code licence to use the POP3 Module can be purchased. On completion of the purchase, Ferrysoft will email the password of the protected zip file to the purchaser to enable the POP3 Module to be extracted for use.

Download

ferrysoft.pop3.zip

The POP3 Module is priced in Pounds Sterling (GBP), US Dollars (USD) and Euros (EUR).

Ferrysoft POP3 Module Price Google PayPal
Royalty-free source code licence (GBP) £99
Royalty-free source code licence (USD) $199 -
Royalty-free source code licence (EUR) €149 -

Summary

The Ferrysoft POP3 Module provides the capability to interrogate a POP3 server for available emails, download the emails and return them to the calling program.

Summary of methods provided by the class

The methods provided by the class are described in the following table.

Method Use
Capability Used to send the capa command to the server which will respond with a list of capabilities if the capa command is supported by the server.
Close Used to send the quit command to the server and then close the connection to the server.
DeleteMessage Used to delete the specified message from the server.
GetMailboxStatus Used to retrieve the mailbox statistics of MessageCount and MailboxSize.
GetMessage Used to retrieve the specified message from the server.
GetMessageHeader Used to retrieve the specified message header from the server.
KeepAlive Used to send the noop command to the server and so keep the session alive.
Open Used to send the authentication details to the server and prepare the connection for subsequent communication with the server.
RollbackDeletes Used to reset the session with the server so that any messages marked for deletion in this session are no longer marked for deletion.

Summary of properties provided by the class

The properties provided by the class are described in the following table.

Property Use
AlternateViews Get the collection of alternate views for the most recently retrieved message. A multipart message may contain text parts in alternate formats (for example text/plain or text/html). If the message is not multipart then the message text is contained in the first and only alternate view. Each text part is contained in an alternate view class. Each alternate view class contains Content, ContentType (MediaType and CharSet) and ContentTransferEncoding (Mechanism).
Attachments Get the collection of attachments for the most recently retrieved message. Each attachment is contained in an attachment class. Each attachment class contains Content, ContentSize, ContentType (MediaType and CharSet), ContentTransferEncoding (Mechanism) and ContentDisposition (DispositionType, FileName, Size, CreationDate, ModificationDate and ReadDate).
LastCommandSent Get the last command sent to the server.
LastResponseOK Get a true/false indicator of whether the last response from the server was an OK response.
LastResponseReceived Get the last response received from the server.
MailboxSize Get the size (number of octets) for the most recently opened mailbox.
MessageCount Get the number of messages for the most recently opened mailbox.
MessageHeaders Get the collection of message headers for the most recently retrieved message.
MessageSize Get the size (number of octets) for the most recently retrieved message.
State Get the connection state.

Capability method

Syntax

Visual Basic
Public Sub Capability()
C#
public void Capability()

Close method

Syntax

Visual Basic
Public Sub Close()
C#
public void Close()

DeleteMessage method

Syntax

Visual Basic
Public Sub DeleteMessage( _
    ByVal MessageNumber As Integer)
C#
public void DeleteMessage(
    int MessageNumber)

Parameters

MessageNumber
The message number (1-n) of the message to delete from the server.

GetMailboxStatus method

Syntax

Visual Basic
Public Sub GetMailboxStatus()
C#
public void GetMailboxStatus()

GetMessage method

Syntax

Visual Basic
Public Sub GetMessage( _
    ByVal MessageNumber As Integer)
C#
public void GetMessage(
    int MessageNumber)

Parameters

MessageNumber
The message number (1-n) of the message to retrieve from the server.

GetMessageHeader method

Syntax

Visual Basic
Public Sub GetMessageHeader( _
    ByVal MessageNumber As Integer)
C#
public void GetMessageHeader(
    int MessageNumber)

Parameters

MessageNumber
The message number (1-n) of the message header to retrieve from the server.

KeepAlive method

Syntax

Visual Basic
Public Sub KeepAlive()
C#
public void KeepAlive()

Open method

Syntax

Visual Basic
Public Sub Open( _
    ByVal Pop3Server As String, _
    ByVal Pop3Port As Integer, _
    ByVal Pop3Encrypted As Boolean, _
    ByVal Pop3Username As String, _
    ByVal Pop3Password As String)
C#
public void Open(
    string Pop3Server,
    int Pop3Port,
    bool Pop3Encrypted,
    string Pop3Username,
    string Pop3Password)

Parameters

Pop3Server
The server name of the POP3 Server. For example, the fictitious server "pop3.example.com".
Pop3Port
The server port number. For an unencrypted connection, the server port number should typically be set to 110. For an encrypted connection, the server port number should typically be set to 995.
Pop3Encrypted
Indicates whether the server requires an encrypted connection. The parameter can be either of the following:
True - Requires an encrypted connection
False - Does not require an encrypted connection
Pop3Username
The username to connect to the server.
Pop3Password
The password to connect to the server.

RollbackDeletes method

Syntax

Visual Basic
Public Sub RollbackDeletes()
C#
public void RollbackDeletes()

AlternateViews property

Syntax

Visual Basic
Public ReadOnly Property AlternateViews As System.Collections.ArrayList
C#
public System.Collections.ArrayList AlternateViews { get; }

Using the AlternateViews property

Get the collection of alternate views for the most recently retrieved message. A multipart message may contain text parts in alternate formats (for example text/plain or text/html). If the message is not multipart then the message text is contained in the first and only alternate view. Each text part is contained in an alternate view class. Each alternate view class contains Content, ContentType (MediaType and CharSet) and ContentTransferEncoding (Mechanism).

Attachments property

Syntax

Visual Basic
Public ReadOnly Property Attachments As System.Collections.ArrayList
C#
public System.Collections.ArrayList Attachments { get; }

Using the Attachments property

Get the collection of attachments for the most recently retrieved message. Each attachment is contained in an attachment class. Each attachment class contains Content, ContentSize, ContentType (MediaType and CharSet), ContentTransferEncoding (Mechanism) and ContentDisposition (DispositionType, FileName, Size, CreationDate, ModificationDate and ReadDate).

LastCommandSent property

Syntax

Visual Basic
Public ReadOnly Property LastCommandSent As String
C#
public string LastCommandSent { get; }

Using the LastCommandSent property

Get the last command sent to the server.

LastResponseOK property

Syntax

Visual Basic
Public ReadOnly Property LastResponseOK As Boolean
C#
public bool LastResponseOK { get; }

Using the LastResponseOK property

Get a true/false indicator of whether the last response from the server was an OK response.

LastResponseReceived property

Syntax

Visual Basic
Public ReadOnly Property LastResponseReceived As String
C#
public string LastResponseReceived { get; }

Using the LastResponseReceived property

Get the last response received from the server.

MailboxSize property

Syntax

Visual Basic
Public ReadOnly Property MailboxSize As Long
C#
public long MailboxSize { get; }

Using the MailboxSize property

Get the size (number of octets) for the most recently opened mailbox.

MessageCount property

Syntax

Visual Basic
Public ReadOnly Property MessageCount As Integer
C#
public int MessageCount { get; }

Using the MessageCount property

Get the number of messages for the most recently opened mailbox.

MessageHeaders property

Syntax

Visual Basic
Public ReadOnly Property MessageHeaders _
    As System.Collections.Generic.Dictionary(Of Integer, String)
C#
public System.Collections.Generic.Dictionary<int, string> MessageHeaders { get; }

Using the MessageHeaders property

Get the collection of message headers for the most recently retrieved message. The collection can be accessed sequentially or selectively using any of the following enumerations of Ferrysoft.Pop3.MessageHeaderType:
Bcc
Cc
ContentDescription
ContentDisposition
ContentDispositionCreationDate
ContentDispositionDispositionType
ContentDispositionFileName
ContentDispositionModificationDate
ContentDispositionReadDate
ContentDispositionSize
ContentID
ContentTransferEncoding
ContentType
ContentTypeBoundary
ContentTypeCharSet
ContentTypeMediaType
Date
From
FromEmailAddress
InReplyTo
MessageID
MIMEVersion
References
ReplyTo
Sender
Subject
To

MessageSize property

Syntax

Visual Basic
Public ReadOnly Property MessageSize As Integer
C#
public int MessageSize { get; }

Using the MessageSize property

Get the size (number of octets) for the most recently retrieved message.

State property

Syntax

Visual Basic
Public ReadOnly Property State As Ferrysoft.Pop3.ConnectionState
C#
public Ferrysoft.Pop3.ConnectionState State { get; }

Using the State property

Get the connection state. The connection state can be returned as any of the following enumerations of Ferrysoft.Pop3.ConnectionState:
Closed
Open

Example Use

The code below shows an example of how to use the POP3 client class.

Visual Basic
'
'   This example uses the POP3 object to connect
'   to a POP3 server and process any messages
'   waiting in the mailbox. For each message,
'   the message headers, alternate views and
'   attachments are shown.
'
Dim Pop3Client As Ferrysoft.Pop3.Client
Dim Pop3Server As String
Dim Pop3Port As Integer
Dim Pop3Encrypted As Boolean
Dim Pop3Username As String
Dim Pop3Password As String
Dim MailboxSize As Long = 0
Dim MessageCount As Integer = 0
Dim MessageSize As Integer = 0
Pop3Client = New Ferrysoft.Pop3.Client()
'
'   Set the Server, Username, Password
'   and Encrypted to the credentials needed
'   in order to connect to your POP3 mailbox.
'   Port is defaulted according to the
'   setting of Encrypted.
'   Port can be overridden if a non-standard
'   port is required to access your POP3 mailbox.
'
Pop3Server = "pop.example.com"
Pop3Username = "myusername"
Pop3Password = "mypassword"
Pop3Encrypted = True
If Pop3Encrypted Then
    Pop3Port = 995
Else
    Pop3Port = 110
End If
Try
    WriteLineString("Init started")
    Pop3Client.Open( _
        Pop3Server, _
        Pop3Port, _
        Pop3Encrypted, _
        Pop3Username, _
        Pop3Password)
    If Pop3Client.LastResponseOK Then
        WriteLineSent(Pop3Client)
        WriteLineReceived(Pop3Client)
        MessageCount = Pop3Client.MessageCount
        MailboxSize = Pop3Client.MailboxSize
        WriteLineValue("Message Count", MessageCount)
        WriteLineValue("Mailbox Size", MailboxSize)
    Else
        WriteLineString("Open failed")
        WriteLineSent(Pop3Client)
        WriteLineReceived(Pop3Client)
    End If
    WriteLineString("Init finished")
Catch
    WriteLineString("EXCEPTION")
End Try
If MessageCount <> 0 Then
    Try
        For MessageNumber = 1 To MessageCount
            Pop3Client.GetMessage(MessageNumber)
            If Pop3Client.LastResponseOK Then
                WriteLineSent(Pop3Client)
                WriteLineOK(Pop3Client)
                MessageSize = Pop3Client.MessageSize
                WriteLineValue("Message Size", MessageSize)
                WriteLineMessageHeadersStyleA(Pop3Client)
                WriteLineMessageHeadersStyleB(Pop3Client)
                WriteLineMessageHeadersStyleC(Pop3Client)
                WriteLineAlternateViews(Pop3Client)
                WriteLineAttachments(Pop3Client)
            Else
                WriteLineString("GetMessage failed")
                WriteLineSent(Pop3Client)
                WriteLineReceived(Pop3Client)
            End If
        Next
    Catch
        WriteLineString("EXCEPTION")
    End Try
End If
Try
    WriteLineString("Term started")
    If Pop3Client.State <> Ferrysoft.Pop3.ConnectionState.Closed Then
        Pop3Client.Close()
        WriteLineSent(Pop3Client)
        WriteLineReceived(Pop3Client)
    End If
    WriteLineString("Term finished")
Catch
    WriteLineString("EXCEPTION")
End Try

Private Sub WriteLineMessageHeadersStyleA( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the message headers.
    '   This style processes each of the members of the collection.
    '
    WriteLineString("Message Header Style A ...")
    For Each KeyValuePair _
        As System.Collections.Generic.KeyValuePair(Of Integer, String) _
        In Pop3Client.MessageHeaders()
        If KeyValuePair.Value.Length <> 0 Then
            System.Console.WriteLine("Key={0} Value={1}", _
                KeyValuePair.Key, KeyValuePair.Value)
        End If
    Next
    WriteLineString("End Message Header")
End Sub

Private Sub WriteLineMessageHeadersStyleB( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the message headers.
    '   This style processes each of the members of the enumeration
    '   MessageHeaderType to obtain the values and names for use in
    '   processing each of the members of the collection.
    '
    WriteLineString("Message Header Style B ...")
    For Each Mht As Ferrysoft.Pop3.MessageHeaderType In _
        Ferrysoft.Pop3.MessageHeaderType.GetValues( _
            GetType(Ferrysoft.Pop3.MessageHeaderType))
        Dim Mhv As String = Pop3Client.MessageHeaders(Mht)
        If Mhv.Length <> 0 Then
            Dim Mhn As String = Ferrysoft.Pop3.MessageHeaderType.GetName( _
                GetType(Ferrysoft.Pop3.MessageHeaderType), Mht)
            System.Console.WriteLine("{0}: {1}", Mhn, Mhv)
        End If
    Next
    WriteLineString("End Message Header")
End Sub

Private Sub WriteLineMessageHeadersStyleC( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the message headers.
    '   This style processes a sample set of specific members of the collection.
    '
    WriteLineString("Message Header Style C ...")
    System.Console.WriteLine("{0}: {1}", "Subject", _
        Pop3Client.MessageHeaders(Ferrysoft.Pop3.MessageHeaderType.Subject))
    System.Console.WriteLine("{0}: {1}", "From", _
        Pop3Client.MessageHeaders(Ferrysoft.Pop3.MessageHeaderType.From))
    System.Console.WriteLine("{0}: {1}", "To", _
        Pop3Client.MessageHeaders(Ferrysoft.Pop3.MessageHeaderType.To))
    WriteLineString("End Message Header")
End Sub

Private Sub WriteLineAlternateViews( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the alternate views.
    '
    WriteLineString("AlternateViews ...")
    For Each AlternateView As Ferrysoft.Pop3.AlternateView _
        In Pop3Client.AlternateViews
        WriteLineAlternateView(AlternateView)
    Next
    WriteLineString("End AlternateViews")
End Sub

Private Sub WriteLineAttachments( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the attachments.
    '
    WriteLineString("Attachments ...")
    For Each Attachment As Ferrysoft.Pop3.Attachment _
        In Pop3Client.Attachments
        WriteLineAttachment(Attachment)
    Next
    WriteLineString("End Attachments")
End Sub

Private Sub WriteLineAlternateView( _
    ByVal AlternateView As Ferrysoft.Pop3.AlternateView)
    '
    '   Show the alternate view.
    '
    WriteLineString("AlternateView ...")
    WriteLineString(AlternateView.ContentType.ToString())
    WriteLineString(AlternateView.ContentTransferEncoding.ToString())
    WriteLineString(AlternateView.Content)
    WriteLineString("End AlternateView")
End Sub

Private Sub WriteLineAttachment( _
    ByVal Attachment As Ferrysoft.Pop3.Attachment)
    '
    '   Show the attachment.
    '
    WriteLineString("Attachment ...")
    WriteLineString(Attachment.ContentType.ToString())
    WriteLineString(Attachment.ContentTransferEncoding.ToString())
    WriteLineString(Attachment.ContentDisposition.ToString())
    WriteLineString("End Attachment")
End Sub

Private Sub WriteLineSent( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the last command sent from the client to the server.
    '
    System.Console.WriteLine("Client: {0}", Pop3Client.LastCommandSent)
End Sub

Private Sub WriteLineReceived( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the last response received from the server by the client.
    '
    System.Console.WriteLine("Server: {0}", Pop3Client.LastResponseReceived)
End Sub

Private Sub WriteLineOK( _
    ByVal Pop3Client As Ferrysoft.Pop3.Client)
    '
    '   Show the OK or ERR response received from the server by the client.
    '
    If Pop3Client.LastResponseOK Then
        WriteLineString("Server: +OK")
    Else
        WriteLineString("Server: -ERR")
    End If
End Sub

Private Sub WriteLineValue( _
    ByVal NameString As String, _
    ByVal ValueLong As Long)
    '
    '   Show a name value pair.
    '
    System.Console.WriteLine("{0}: {1:0}", NameString, ValueLong)
End Sub

Private Sub WriteLineString( _
    ByVal ValueString As String)
    '
    '   Show a string.
    '
    System.Console.WriteLine(ValueString)
End Sub
C#
//
//  This example uses the POP3 object to connect
//  to a POP3 server and process any messages
//  waiting in the mailbox. For each message,
//  the message headers, alternate views and
//  attachments are shown.
//
Ferrysoft.Pop3.Client Pop3Client;
string Pop3Server;
int Pop3Port;
bool Pop3Encrypted;
string Pop3Username;
string Pop3Password;
long MailboxSize = 0;
int MessageCount = 0;
int MessageSize = 0;
Pop3Client = new Ferrysoft.Pop3.Client();
//
//  Set the Server, Username, Password
//  and Encrypted to the credentials needed
//  in order to connect to your POP3 mailbox.
//  Port is defaulted according to the
//  setting of Encrypted.
//  Port can be overridden if a non-standard
//  port is required to access your POP3 mailbox.
//
Pop3Server = "pop.example.com";
Pop3Username = "myusername";
Pop3Password = "mypassword";
Pop3Encrypted = true;
if (Pop3Encrypted)
    Pop3Port = 995;
else
    Pop3Port = 110;
try
{
    WriteLineString("Init started");
    Pop3Client.Open(
        Pop3Server,
        Pop3Port,
        Pop3Encrypted,
        Pop3Username,
        Pop3Password);
    if (Pop3Client.LastResponseOK)
    {
        WriteLineSent(Pop3Client);
        WriteLineReceived(Pop3Client);
        MessageCount = Pop3Client.MessageCount;
        MailboxSize = Pop3Client.MailboxSize;
        WriteLineValue("Message Count", MessageCount);
        WriteLineValue("Mailbox Size", MailboxSize);
    }
    else
    {
        WriteLineString("Open failed");
        WriteLineSent(Pop3Client);
        WriteLineReceived(Pop3Client);
    }
    WriteLineString("Init finished");
}
catch
{
    WriteLineString("EXCEPTION");
}
if (MessageCount != 0)
{
    try
    {
        for (int MessageNumber = 1;
            MessageNumber <= MessageCount; MessageNumber++)
        {
            Pop3Client.GetMessage(MessageNumber);
            if (Pop3Client.LastResponseOK)
            {
                WriteLineSent(Pop3Client);
                WriteLineOK(Pop3Client);
                MessageSize = Pop3Client.MessageSize;
                WriteLineValue("Message Size", MessageSize);
                WriteLineMessageHeadersStyleA(Pop3Client);
                WriteLineMessageHeadersStyleB(Pop3Client);
                WriteLineMessageHeadersStyleC(Pop3Client);
                WriteLineAlternateViews(Pop3Client);
                WriteLineAttachments(Pop3Client);
            }
            else
            {
                WriteLineString("GetMessage failed");
                WriteLineSent(Pop3Client);
                WriteLineReceived(Pop3Client);
            }
        }
    }
    catch
    {
        WriteLineString("EXCEPTION");
    }
}
try
{
    WriteLineString("Term started");
    if (Pop3Client.State != Ferrysoft.Pop3.ConnectionState.Closed)
    {
        Pop3Client.Close();
        WriteLineSent(Pop3Client);
        WriteLineReceived(Pop3Client);
    }
    WriteLineString("Term finished");
}
catch
{
    WriteLineString("EXCEPTION");
}
private static void WriteLineMessageHeadersStyleA(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the message headers.
    //  This style processes each of the members of the collection.
    //
    WriteLineString("Message Header Style A ...");
    foreach (System.Collections.Generic.KeyValuePair<int, string> KeyValuePair in
        Pop3Client.MessageHeaders)
    {
        if (KeyValuePair.Value.Length != 0)
            System.Console.WriteLine("Key={0} Value={1}",
                KeyValuePair.Key, KeyValuePair.Value);
    }
    WriteLineString("End Message Header");
}
private static void WriteLineMessageHeadersStyleB(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the message headers.
    //  This style processes each of the members of the enumeration
    //  MessageHeaderType to obtain the values and names for use in
    //  processing each of the members of the collection.
    //
    WriteLineString("Message Header Style B ...");
    foreach (Ferrysoft.Pop3.MessageHeaderType Mht in
        Ferrysoft.Pop3.MessageHeaderType.GetValues(
            typeof(Ferrysoft.Pop3.MessageHeaderType)))
    {
        string Mhv = Pop3Client.MessageHeaders[(int)Mht];
        if (Mhv.Length != 0)
        {
            string Mhn = Ferrysoft.Pop3.MessageHeaderType.GetName(
                typeof(Ferrysoft.Pop3.MessageHeaderType), Mht);
            System.Console.WriteLine("{0}: {1}", Mhn, Mhv);
        }
    }
    WriteLineString("End Message Header");
}
private static void WriteLineMessageHeadersStyleC(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the message headers.
    //  This style processes a sample set of specific members of the collection.
    //
    WriteLineString("Message Header Style C ...");
    System.Console.WriteLine("{0}: {1}", "Subject",
        Pop3Client.MessageHeaders[(int)Ferrysoft.Pop3.MessageHeaderType.Subject]);
    System.Console.WriteLine("{0}: {1}", "From",
        Pop3Client.MessageHeaders[(int)Ferrysoft.Pop3.MessageHeaderType.From]);
    System.Console.WriteLine("{0}: {1}", "To",
        Pop3Client.MessageHeaders[(int)Ferrysoft.Pop3.MessageHeaderType.To]);
    WriteLineString("End Message Header");
}
private static void WriteLineAlternateViews(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the alternate views.
    //
    WriteLineString("AlternateViews ...");
    foreach (Ferrysoft.Pop3.AlternateView AlternateView
        in Pop3Client.AlternateViews)
    {
        WriteLineAlternateView(AlternateView);
    }
    WriteLineString("End AlternateViews");
}
private static void WriteLineAttachments(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the attachments.
    //
    WriteLineString("Attachments ...");
    foreach (Ferrysoft.Pop3.Attachment Attachment
        in Pop3Client.Attachments)
    {
        WriteLineAttachment(Attachment);
    }
    WriteLineString("End Attachments");
}
private static void WriteLineAlternateView(
    Ferrysoft.Pop3.AlternateView AlternateView)
{
    //
    //  Show the alternate view.
    //
    WriteLineString("AlternateView ...");
    WriteLineString(AlternateView.ContentType.ToString());
    WriteLineString(AlternateView.ContentTransferEncoding.ToString());
    WriteLineString(AlternateView.Content);
    WriteLineString("End AlternateView");
}
private static void WriteLineAttachment(
    Ferrysoft.Pop3.Attachment Attachment)
{
    //
    //  Show the attachment.
    //
    WriteLineString("Attachment ...");
    WriteLineString(Attachment.ContentType.ToString());
    WriteLineString(Attachment.ContentTransferEncoding.ToString());
    WriteLineString(Attachment.ContentDisposition.ToString());
    WriteLineString("End Attachment");
}
private static void WriteLineSent(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the last command sent from the client to the server.
    //
    System.Console.WriteLine("Client: {0}", Pop3Client.LastCommandSent);
}
private static void WriteLineReceived(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the last response received from the server by the client.
    //
    System.Console.WriteLine("Server: {0}", Pop3Client.LastResponseReceived);
}
private static void WriteLineOK(
    Ferrysoft.Pop3.Client Pop3Client)
{
    //
    //  Show the OK or ERR response received from the server by the client.
    //
    if (Pop3Client.LastResponseOK)
        WriteLineString("Server: +OK");
    else
        WriteLineString("Server: -ERR");
}
private static void WriteLineValue(
    string NameString,
    long ValueLong)
{
    //
    //  Show a name value pair.
    //
    System.Console.WriteLine("{0}: {1:0}", NameString, ValueLong);
}
private static void WriteLineString(
    string ValueString)
{
    //
    //  Show a string.
    //
    System.Console.WriteLine(ValueString);
}

In the example below, the above code is run against a POP3 server with two messages waiting in the user's mailbox. It produces the following output:

Init started
Client: STAT
Server: +OK 2 4852
Message Count: 2
Mailbox Size: 4852
Init finished
Client: RETR 1
Server: +OK
Message Size: 2421
Message Header Style A ...
Key=11 Value=7bit
Key=12 Value=text/plain; charset="us-ascii"
Key=14 Value=us-ascii
Key=15 Value=text/plain
Key=16 Value=Wed, 7 Oct 2009 17:17:04 +0100
Key=17 Value="John Doe" <john.doe@example.com>
Key=18 Value=john.doe@example.com
Key=20 Value=<000b01ca4769$9c678a90$d5369fb0$@doe@example.com>
Key=21 Value=1.0
Key=25 Value=Test Message A
Key=26 Value=<jane.doe@example.com>
End Message Header
Message Header Style B ...
ContentTransferEncoding: 7bit
ContentType: text/plain; charset="us-ascii"
ContentTypeCharSet: us-ascii
ContentTypeMediaType: text/plain
Date: Wed, 7 Oct 2009 17:17:04 +0100
From: "John Doe" <john.doe@example.com>
FromEmailAddress: john.doe@example.com
MessageID: <000b01ca4769$9c678a90$d5369fb0$@doe@example.com>
MIMEVersion: 1.0
Subject: Test Message A
To: <jane.doe@example.com>
End Message Header
Message Header Style C ...
Subject: Test Message A
From: "John Doe" <john.doe@example.com>
To: <jane.doe@example.com>
End Message Header
AlternateViews ...
AlternateView ...
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
This is test message A.

It is a single-part plain text message.

End AlternateView
End AlternateViews
Attachments ...
End Attachments
Client: RETR 2
Server: +OK
Message Size: 2431
Message Header Style A ...
Key=11 Value=7bit
Key=12 Value=text/plain; charset="us-ascii"
Key=14 Value=us-ascii
Key=15 Value=text/plain
Key=16 Value=Wed, 7 Oct 2009 17:17:16 +0100
Key=17 Value="John Doe" <john.doe@example.com>
Key=18 Value=john.doe@example.com
Key=20 Value=<000c01ca4769$a32aa6a0$e97ff3e0$@doe@example.com>
Key=21 Value=1.0
Key=25 Value=Test Message B
Key=26 Value=<jane.doe@example.com>
End Message Header
Message Header Style B ...
ContentTransferEncoding: 7bit
ContentType: text/plain; charset="us-ascii"
ContentTypeCharSet: us-ascii
ContentTypeMediaType: text/plain
Date: Wed, 7 Oct 2009 17:17:16 +0100
From: "John Doe" <john.doe@example.com>
FromEmailAddress: john.doe@example.com
MessageID: <000c01ca4769$a32aa6a0$e97ff3e0$@doe@example.com>
MIMEVersion: 1.0
Subject: Test Message B
To: <jane.doe@example.com>
End Message Header
Message Header Style C ...
Subject: Test Message B
From: "John Doe" <john.doe@example.com>
To: <jane.doe@example.com>
End Message Header
AlternateViews ...
AlternateView ...
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
This is test message B.

It is a single-part plain text message.

End AlternateView
End AlternateViews
Attachments ...
End Attachments
Term started
Client: QUIT
Server: +OK Farewell.
Term finished