Introduction
This article gives a small idea as to how we can retrieve the mails from any server.
Background
The POP3 protocol is used to allow a workstation to retrieve mail that the server is holding for it. Initially, the server host starts the POP3 service by listening on TCP port 110. When a client host wishes to make use of the service, it establishes a TCP connection with the server host. When the connection is established, the POP3 server sends a greeting.
Using the code
The working of the code is as follows:- Once the connection with the server is established,the server authenticates the user name and the password and then retrieves the mails. The POP3 protocol has certain commands which it uses for authentication and for retieval of mails. Below is the function which makes use of the various commands to retrieve the mails. 1.CONNECT this is used to connect to the server. 2.USER this is used to authenticate the user name. 3.PASS this is used to authenticate the password. 4.STAT this is used to get the number of messages. 5.QUIT this is used to disconnect from the server.
void Tapp::ProcessPop3Commands(enum eCommands pCommand,HWND pHwnd)
{
switch(pCommand) {
case CONNECT:
char* address; char* portno;
address=vWin.RetrieveText(GetDlgItem(pHwnd,IDC_EDITBOX3));
portno=vWin.RetrieveText(GetDlgItem(pHwnd,IDC_EDITBOX4));
if(vPop.MakeConnection(address,portno)==TRUE){
free(address);
free(portno);
vPop.RecvInfoFromServer();
MessageBox(pHwnd, vPop.Getresponse(), "Message",MB_OK);
pCommand=USER;
}else{
free(address);
free(portno);
break;
}
case USER:
{
char *username;
username=vWin.RetrieveText(GetDlgItem(pHwnd,IDC_EDITBOX1));
if(vPop.SendInformation("USER",username,pHwnd)==TRUE){
free(username);
pCommand=PASS;
}else{
free(username);
pCommand=QUIT;
}
}
case PASS:
{
char *password;