Click here to Skip to main content
11,926,429 members (56,082 online)
Click here to Skip to main content
Add your own
alternative version


39 bookmarked

CPop3 class

, 31 Mar 2002
Rate this:
Please Sign up or sign in to vote.
This is simple CPop3 class that can connect to a pop3 server and receive messages.

Sample Image


This is simple CPop3 class that can connect to a pop3 server and receive messages. What is the difference between this and other pop3 classes (ie. PJ Naughter's)? Well, first of all - it's mine Smile | :) And the second thing - it's an CAsyncSocket derived class, so that's why using it is quite different from other one. Quick info...

How to use it?

Simply I think. The main class is CPop3, so you just create a variable of this type, set-up things, compile and run. Once you've set up stuff, everything will proceed automatically. There is another class - CBase4Pop3 declared in Gniazdo.h - but you usually don't use it directly (see Gniazdo.h).

Step 1 - starting

Create dialog-based app, add Gniazdo.h, Gniazdo.cpp, pop31.h and pop31.cpp files to project, then create a CPop3 variable in CYourDlg class.

Step 2 - setting up things

Edit gniazdo.h file. At the beginning you will se something like this:

#define DLG CPop3Dlg* //change it to your CDialog-based class
Change it to your dialog-based class. And don't forget to include property header files, if necessary. Now in your dialog-based class create a public function called Dispatch:
//your dlg.h file
void Dispatch(LONG param); //declaration
//your dlg.cpp file
void CYourDlg::Dispatch(LONG param)
CString s;
case S_CONNECT: //we are connected
	//your code on OnConnect event
case S_RECEIVE: //OnReceive
//and so on...
So now, every message which comes to CPop3 will be passed to your function.

Step 3 - obtaining information

How to handle messages? Check out pop3Dlg.cpp for details. Basically, you can invoke a CPop3::GetLastMsg(CString &s) to get the most recent data from server. Other functions works similar, so you shouldn't have any problems with using them. There are currently 6 scoket messages:

#define S_CLOSE 1 //send when we are about to close connection
#define S_CONNECT 2 //send when we have just connected to a server
#define S_RECEIVE 3 //we are receiving some stuff
//and additional
#define S_GETNUMMSGS 5 //send when user can obtain number of messages
#define S_GETSIZEMSGS 6 //as above, but size of messages
#define S_ENDRETR 7 //send when done retrieving

Step 4 - initialization

First, make sure you have AfxInitSocket in your InitInstance. Second set parent window, user, password, server and connect to a server:

void CYourDlg::OnConnectBtn() 
	// TODO: Add your control notification handler code here
	pop3.Set(this); //set window that will receive messages
	pop3.SetProp(user,pass); //set user and pass
	pop3.DelAfterRead(del); //want to delete messages from server?
	pop3.Create(); //create socket
	pop3.Connect((LPCSTR)server,110); //connect to a server

Final step...

Once you've successfully connected to a server, everything will do automatically, that is check for messages, get them, also if you wish delete them and disconnect. When it receives an error, the class will disconnect from the server. To view a message simply call CString CPop3::GetMsgStuff(int i) and CString CPop3::GetMsgBody(int i) where i stands for the message number. CString CPop3::GetMsg(int i) returns all of the message. After sending a S_ENDRETR message (= all of messages have been received) and S_CLOSE, the class will disconnect from server. For other useful functions see pop31.h file.

Hope you like it!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

Generaldo not wotk with gmail Pin
Balkrishna Talele31-Mar-09 21:48
memberBalkrishna Talele31-Mar-09 21:48 
GeneralRe: do not wotk with gmail Pin
Pogo Lin12-Jan-10 22:26
memberPogo Lin12-Jan-10 22:26 
Generalbuffer overrun Pin
imagiro25-Aug-07 0:54
memberimagiro25-Aug-07 0:54 
QuestionHow can I judge the mail has been read?? Pin
Karlzheng9-Nov-06 23:43
memberKarlzheng9-Nov-06 23:43 
QuestionReceive Attachment? Pin
dragomir5-Jan-06 5:13
memberdragomir5-Jan-06 5:13 
GeneralGreat work friend! Pin
Georgi Petrov2-Jun-05 10:04
memberGeorgi Petrov2-Jun-05 10:04 
GeneralRe: Great work friend! Pin
chris myself5-Jun-05 12:12
susschris myself5-Jun-05 12:12 
GeneralLIST/UIDL commands Pin
Andrew Kennard12-Apr-05 3:35
memberAndrew Kennard12-Apr-05 3:35 
GeneralGet the Attachment Pin
Gajalakshmi Krishnan11-Apr-05 6:41
memberGajalakshmi Krishnan11-Apr-05 6:41 
GeneralRe: Get the Attachment Pin
xinxin062923-Jun-07 19:59
memberxinxin062923-Jun-07 19:59 
GeneralReceiving of messages Pin
marinrm30-Nov-04 5:07
membermarinrm30-Nov-04 5:07 
GeneralProblem with RETR command Pin
unpatrice5-May-04 0:18
memberunpatrice5-May-04 0:18 
GeneralSend an attachment Pin
Tjie Pouw15-Feb-04 5:01
memberTjie Pouw15-Feb-04 5:01 
GeneralHTML TXT messages Pin
MMs_xH8-Jul-03 7:40
memberMMs_xH8-Jul-03 7:40 
GeneralRe: HTML TXT messages Pin
kubrick7-Dec-03 8:00
memberkubrick7-Dec-03 8:00 
GeneralI added TOP pop3 command Pin
forjunkmail25-May-03 19:57
memberforjunkmail25-May-03 19:57 
QuestionCan we implement this CPop3 class in an DLL without any window? Pin
abirnale7-May-03 22:31
memberabirnale7-May-03 22:31 
Generalassert Pin
Sonu Kapoor20-Mar-03 22:31
memberSonu Kapoor20-Mar-03 22:31 
GeneralAbout RETR command Pin
Mamtha26-Dec-02 3:17
sussMamtha26-Dec-02 3:17 
GeneralRe: About RETR command Pin
eggie514-Jun-04 17:29
membereggie514-Jun-04 17:29 
Generala bug in CPop3Connection::ReadResponse Pin
sunnet_wang14-Oct-02 17:43
membersunnet_wang14-Oct-02 17:43 
GeneralPOP3 protocol Pin
deepak_kesarwani@satyam.com6-Aug-02 0:52
sussdeepak_kesarwani@satyam.com6-Aug-02 0:52 
GeneralBug in CPop3Connection::ReadUIDLResponse(int nNumberOfMails) Pin
Martin Eckardt15-Jul-02 23:06
memberMartin Eckardt15-Jul-02 23:06 
QuestionHow to do it through proxy server Pin
Anonymous2-Apr-02 18:31
memberAnonymous2-Apr-02 18:31 
AnswerRe: How to do it through proxy server Pin
Christopher Zmo...blah....blah...2-Apr-02 19:33
memberChristopher Zmo...blah....blah...2-Apr-02 19:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 1 Apr 2002
Article Copyright 2002 by Christopher Zmorzynski
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid