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
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
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 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
void Dispatch(LONG param); void CYourDlg::Dispatch(LONG param)
case S_CONNECT: break;
So now, every message which comes to
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 #define S_CONNECT 2 #define S_RECEIVE 3 #define S_GETNUMMSGS 5 #define S_GETSIZEMSGS 6 #define S_ENDRETR 7
Step 4 - initialization
First, make sure you have
AfxInitSocket in your
InitInstance. Second set parent window, user, password, server and connect to a server:
pop3.SetProp(user,pass); pop3.DelAfterRead(del); pop3.Create(); pop3.Connect((LPCSTR)server,110); UpdateData(FALSE);
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
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!