POP3 Wrapper Class 2001


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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


Download demo project - 14 Kb
Download source - 4 Kb


  • How to download

    Posted by Legacy on 12/23/2003 08:00am

    Originally posted by: Eric Brown

    Using http://de.geocities.com/janraddatz/downloads/POP3.zip doesn't work for me. But go to http://de.geocities.com/janraddatz/downloads and selecting POP3.zip from there does.

  • Where are files to download ???

    Posted by Legacy on 09/03/2003 07:00am

    Originally posted by: matrix666

    I cannot download files ...
    broken links ...
    I need this class

  • CheckResponse code needs altering ... slightly

    Posted by Legacy on 05/23/2003 07:00am

    Originally posted by: Duncan Weir

    where it checks the following codes

    the code currently checks for end of buffer by looking for the last 3 chars being .\r\n

    BUT some emails can screw this check up.

    For instance i had an email that had a subject line ending in ....\r\n

    in this case the code thought it had reached the end of the buffer when in fact is was only part way through.

    Solution is to alter the code to look for \n.\r\n

    Hope this helps.

  • Getting just the header - sometimes a problem

    Posted by Legacy on 05/19/2003 07:00am

    Originally posted by: Duncan Weir

    Just a note that after extensive testing with this class in an anti-spam application i'm writing, i've found that the command GetTop works best if you do:

    GetTop(<message number>,1);

    Doing GetTop(<message number>,0); works the majority of the time, but sometimes it times out and retrieves nothing !

  • New URL the Third

    Posted by Legacy on 04/29/2003 07:00am

    Originally posted by: Jan Raddatz

    Hello again,
    here is a new URL to download the POP3 Wrapper class.
    It's on a fortunecity account and should work finally.


    If you have any questions or problems using the class feel free to drop me an e-mail. :-)

    Greetings to all codegurus

  • no Connect after Disconnect :(

    Posted by Legacy on 04/13/2003 07:00am

    Originally posted by: Marco Gohl

    I connect to the server and get my mails, but after
    i disconnect then I can't connect again :(

    "Server cannot be connected"...

    How can I solve this Problem?

  • URL Fix 2nd

    Posted by Legacy on 04/09/2003 07:00am

    Originally posted by: Jan Raddatz

    I posted the new URL a few days ago.

    The problem is that it seems not to work for some people.
    I will get a new domain soon and publish the new URL to the files soon here.

    If the geocities link does not work for you (It worked for me) feel free to post me a mail and I will send you the files immediately.

    mail: jan-raddatz@web.de


  • URL Fix 09.03.2003

    Posted by Legacy on 03/09/2003 08:00am

    Originally posted by: Jan Raddatz

    due to ISP problems I had to move my website and so the URL's were broken.

    Here is the fixed URL to the POP3 Wrapper class source code.

    It's a zipped file.



  • pop3

    Posted by Legacy on 02/09/2003 08:00am

    Originally posted by: prasad

    very nice project

  • URL's for source/project are down :-(

    Posted by Legacy on 05/12/2002 07:00am

    Originally posted by: Agent_White

    Does anybody know the new url where i can download the source / demo project ???
    Maybe it's possible that someone could mail this files to Agent_White@hotmail.com !!!

    thanx in advance.

    cu Agent_White

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date