How to POP3 in C#

Getting Started

I usually begin writing new classes by introducing an exception class that I can use to throw and catch all exceptions of the class.

public class Pop3Exception : System. ApplicationException
{
    public Pop3Exception( string str)
        : base( str)
    {
    }
}

I will not explain the exception class, but rather I expect the reader have enough expertise with C# to understand this exception class before reading the rest of the article.

Next I created a small class that defines a POP3 message.

public class Pop3Message
{
    public long number;
    public long bytes;
    public bool retrieved;
    public string message;
}

When you retrieve lists of POP3 messages from a POP3 server, the list includes a message number and number of bytes. You can then use the message number to retrieve the message content. You'll see this later when we define our List and Retrieve methods. We derive our Pop3 class from the System. Net.Sockets.TcpClient class in the .NET framework.

public class Pop3 : System.Net.Sockets.TcpClient {

The TcpClient class and the other classes in the System.Net.Sockets namespace of the .NET framework are great encapsulations of the familiar function-oriented socket library.

You might also like...

Comments

About the author

Randy Charles Morin

Randy Charles Morin Canada

Randy's article are Copyright 1998-2003 Randy Charles Morin

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”