POP3 Wrapper Class 2001

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:

enum DataTypes

class CPOP3Handler

bool Connect
(LPCTSTR p_User, LPCTSTR p_Password,
LPCTSTR p_Host, int p_Port = 110);

bool Disconnect();

bool Statistics ();
bool Delete
(int p_MsgNumber);

bool Noop ();
bool Reset ();
bool Retrieve
(int p_MsgNumber);

bool Retrieve
(int p_MsgNumber, LPCTSTR p_pTargetFileName);

bool List ();
bool GetTop
(int p_MsgNumber, int p_Length);

bool SetOutputFile
(LPCTSTR p_OutputFileName);

int GetNumberNewMails ();
int GetTotalMailSize ();

CString Get
(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.


CPOP3Handler POP3;
POP3.Connect ("Username", "Password", pop.host.de, 110);
CString List;
CString Header;
CString WholeMail;

// use one of the enum values to tell GET which data type
// to return.


// 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.


Download demo project – 14 Kb

Download source – 4 Kb

More by Author

Must Read