POP3 Servers and Commands

Receive Email Walkthrough: for C# and VB NET Students

 

You have just seen how to send emails through a SMTP server. What we're going to do now is to connect to a POP3 server like the ones you have with your ISP or your web host, and check if there's any emails waiting. If there are, then we'll download them. You need to know something about how POP3 servers work first, though.


POP3 Servers

When you receive emails with a client like Outlook, what you are doing is talking to a POP3 server. The POP3 server is listening all the time on a specific port for any incoming connections. When you try to connect for the first time, you enter what's known as the Handshake process. This is when you send a command to the server asking if it's available. If it is, the server will say so, and ask for your login credentials. If they are accepted, the connection to the server stays open, waiting for your commands. There are generally 4 steps in the whole process:

Connection
Authorisation
Transaction
Update

The Connection step is when you wake the POP3 server up with your handshake. The Authorisation step is when you send the POP3 server your credentials. If these are accepted, the POP3 server waits for your commands. This is the Transaction step. When you are finished, you issue a Quit command. The server then takes care of any Updates you made, such as deleting emails. (If the POP3 Server doesn't receive the Quit command then no updates get made. It might not receive an Update command, for example, if your programme crashes.)

The response you get for a POP3 server is either +OK or -ERR.

POP3 Commands

Most POP3 servers will recognise the following commands (not case sensitive):

USER
PASS
LIST
STAT
NOOP
RETR
RSET
DELE
QUIT

Here's a rundown of what they do. You can probably guess most of them.

USER - Your username to logon to the POP3 server.

PASS - Your password to logon to the POP3 server.

LIST - Gets a list of all the emails you have waiting for you.

STAT - Gets statistics about the emails. These are how many emails are waiting, and the total size. The total size is in Octets. This is important for your programming. An Octet is a group of eight bits (1 Byte), so we're going to have to work with bit manipulation when dealing with the POP3 server. It's not too painful, though!

NOOP - Stands for No Operation. You can issue the NOOP command just to check if the server's still there.

RETR - Used to retrieve email messages from the server.

DELE - Used to delete emails from the server.

QUIT - Starts the update process on the POP3 server, and then ends a session. If you've issued any delete commands, they won't get executed until the server receives the QUIT command. Otherwise, the server doesn't get updated.


Now that you have a general idea of how POP3 servers work, let's get started on some programming.

.NET Code and the POP3 Server >>

Back to the C# NET Contents Page

Back to the VB NET Contents Page