Right. I’d like to do it more to see how it is done than anything.
I understand using POP3, IMAP and SMTP from a client, but not form code.
To understand how it is done, the best would be to read the RFCs on the web (or invest in the book by Wright/Stevens).
Basically they all work more or less the same:
You make a simple socket connection, and you send a 4-byte command (such as USER, PASS, RCPT, or STAT) telling the server what you want, and you get back a reply. You can play with this via telnet. Try
telnet yourpop3server 110, then type
USER yourusername, followed by
PASS yourpassword, and then
STAT. You'll get a listing of your mail (if there is any) and you can then for example use
RETR 1 to get message number 1.
A mail client does nothing else. Well, a bit more maybe, since there are other authentication methods than plaintext passwords, and many advanced features... but basically that's it.
You have to know what the commands are and when you may use which one, all of that is well documented in the RFCs.
A working open source implementation is for example in PHP and (obviously) Thunderbird.