Environment: [VC6 SP4, Win9X, Win2k, Win NT 4.0]
Looking at the publishing date of Robert E. Peters’ article I decided to write a new and updated POP3 Wrapper Class.
Fixed or Changed:
I restructured the class and replaced the #define constants through enums. I also figured out a few accidentally made bugs in the old POP3 class and fixed them. For example the implementation of the LIST
command where Robert E. Peters sent one space character too much which resulted in -ERR by a few POP3 servers.
The returned data of the LIST, RETR and TOP command can now be bufferd in a temp file or be directly returned (unbuffered). This assumes that you don’t have too big mails.
Here are the most important procedures of the new POP3 Class:
(LPCTSTR p_User, LPCTSTR p_Password,
LPCTSTR p_Host, int p_Port = 110);
bool Statistics ();
bool Noop ();
bool Reset ();
(int p_MsgNumber, LPCTSTR p_pTargetFileName);
bool List ();
(int p_MsgNumber, int p_Length);
int GetNumberNewMails ();
int GetTotalMailSize ();
(int p_DataType, int p_MessageNumber = 1);
CString GetErrorMessage ();
After calling Connect you can easily use the Get command to retrieve Mail-Headers, Complete Mails or a List of mails.
POP3.Connect ("Username", "Password", pop.host.de, 110);
// use one of the enum values to tell GET which data type
// to return.
List = POP3.Get (LIST_AS_STRING);
// Here you need to specify the e-mail number
// as second parameter.
Header = POP3.Get (TOP_AS_STRING, 1);
WholeMail = POP3.Get (MAIL_AS_STRING, 1);
The rest of this class is self explaining in my oppinion. If you have problems using this class, bugs or ideas send a mail at my given mail address.
The Demo is a small console based App which asks for your username, password and POP3 host address. It then does a LIST, TOP and RETR command. The results will be saved in Test.txt at the same directory.