Click here to Skip to main content
Click here to Skip to main content

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

Introduction

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
public:
void Dispatch(LONG param); //declaration
//your dlg.cpp file
void CYourDlg::Dispatch(LONG param)
{
CString s;
switch(param)
{
case S_CONNECT: //we are connected
	//your code on OnConnect event
	break;
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:

//basic
#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
	UpdateData(TRUE);
	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
	UpdateData(FALSE);
}

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!

License

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

Share

About the Author

No Biography provided

Comments and Discussions

 
Generaldo not wotk with gmail PinmemberBalkrishna Talele31-Mar-09 21:48 
GeneralRe: do not wotk with gmail PinmemberPogo Lin12-Jan-10 22:26 
Generalbuffer overrun Pinmemberimagiro25-Aug-07 0:54 
QuestionHow can I judge the mail has been read?? PinmemberKarlzheng9-Nov-06 23:43 
QuestionReceive Attachment? Pinmemberdragomir5-Jan-06 5:13 
GeneralGreat work friend! PinmemberGeorgi Petrov2-Jun-05 10:04 
GeneralRe: Great work friend! Pinsusschris myself5-Jun-05 12:12 
GeneralLIST/UIDL commands PinmemberAndrew Kennard12-Apr-05 3:35 
GeneralGet the Attachment PinmemberGajalakshmi Krishnan11-Apr-05 6:41 
GeneralRe: Get the Attachment Pinmemberxinxin062923-Jun-07 19:59 
GeneralReceiving of messages Pinmembermarinrm30-Nov-04 5:07 
GeneralProblem with RETR command Pinmemberunpatrice5-May-04 0:18 
GeneralSend an attachment PinmemberTjie Pouw15-Feb-04 5:01 
GeneralHTML TXT messages PinmemberMMs_xH8-Jul-03 7:40 
GeneralRe: HTML TXT messages Pinmemberkubrick7-Dec-03 8:00 
GeneralI added TOP pop3 command Pinmemberforjunkmail25-May-03 19:57 
QuestionCan we implement this CPop3 class in an DLL without any window? Pinmemberabirnale7-May-03 22:31 
Generalassert PinmemberSonu Kapoor20-Mar-03 22:31 
GeneralAbout RETR command PinsussMamtha26-Dec-02 3:17 
GeneralRe: About RETR command Pinmembereggie514-Jun-04 17:29 
Generala bug in CPop3Connection::ReadResponse Pinmembersunnet_wang14-Oct-02 17:43 
GeneralPOP3 protocol Pinsussdeepak_kesarwani@satyam.com6-Aug-02 0:52 
GeneralBug in CPop3Connection::ReadUIDLResponse(int nNumberOfMails) PinmemberMartin Eckardt15-Jul-02 23:06 
QuestionHow to do it through proxy server PinmemberAnonymous2-Apr-02 18:31 
AnswerRe: How to do it through proxy server PinmemberChristopher Zmo...blah....blah...2-Apr-02 19:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web01 | 2.8.141223.1 | Last Updated 1 Apr 2002
Article Copyright 2002 by Christopher Zmorzynski
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid