You want to retrieve messages from a POP3 mail server.
Create a dedicated class that sends POP3 commands over a TCP connection.
POP3 is a common e-mail protocol used to download messages from a mail server. POP3, like many Internet protocols, defines a small set of commands that are sent as simple ASCII-encoded messages over a TCP connection (typically on port 110).
Here’s a listing of a typical POP3 dialogue, starting immediately after the client makes a TCP connection:
Server sends:+OK <email@example.com> Client sends:USER <UserName> Server sends:+OK Client sends:PASS <Password> Server sends:+OK Client sends:LIST Server sends:+OK Server sends:<Message list terminated by a period> ...