Click here to Skip to main content
15,891,204 members
Articles / Desktop Programming / MFC
Article

A POP3 class with WIN32 API (APOP Command support)

Rate me:
Please Sign up or sign in to vote.
4.69/5 (25 votes)
3 Jan 20031 min read 187.4K   6.8K   71   39
A POP3 class with WIN32 API

Sample Image - mail.jpg

Introduction

This is a simple POP3 class that can connect to a POP3 server and receive mail. Easy to use.

How to use

Create your project, add pop3.cpp and pop3.h to your project, then you can use it.

Step 1

  • Define a CPop3 variable in your class:

    CPop3 m_pop3handle;

Step 2

  • Create a POP3 connection:

    BOOL Create(LPCSTR pszHostName, int nPort);

Step 3

  • Connect to the POP3 server:

    BOOL Connect(LPCSTR pszUser, LPCSTR pszPassword);

Step 4

  • Get status form server:

    BOOL GetStat(CString *strStat);

  • Get mail list from server:

    BOOL GetMailList(CStringList *strResult);

  • Get a mail header:

    BOOL GetMailHeader(int nMailIndex , CString *strMailHeader);

  • Get a mail sender:

    BOOL GetMailSender(int nMailIndex, CString *strSender);

  • Get a mail receiver:

    BOOL GetMailReceiver(int nMailIndex, CString *strReceiver);

  • Get a mail subject:

    BOOL GetMailSubject(int nMainIndex, CString *strSubject);

  • Get a mail date:

    BOOL GetMailDate(int nMailIndex, CString *strDate);

  • Get a mail size:

    BOOL GetMailSize(int nMailIndex, long *lSize);

  • Get a mail body to memory:

    BOOL GetMail(int nMailIndex , CString *strMail);

  • Get a mail body to a temp file:

    BOOL GetMail(int nMailIndex, LPCSTR tmpfilename);

  • Delete a mail:

    BOOL DeleteMail(int nMailIndex);

  • Reset the mail list:

    BOOL ResetMail();

  • Get last error:

    BOOL GetLastError(CString *msg);

  • Get timeout setting:

    BOOL GetTimeOut(DWORD *dwTimeOut);

  • Set timeout:

    BOOL SetTimeOut(DWORD dwTimeOut);

  • Get the buffer size of receive:

    BOOL GetReceiveBufSize(long *lSize);

  • Set the buffer size of receive:

    BOOL SetReceiveBufSize(long lSize);

Step 5

  • Disconnect from the POP3 server:

    BOOL DisConnect();

Step 6

  • Close socket:

    BOOL Close();

Update

  • 2003.01.06

    Modify connect function:

    BOOL Connect(LPCSTR pszUser, LPCSTR pszPassword , BOOL bAPOPAuthentication);

    parameter 3 is authentication mode, if you want use APOP command, set it to TRUE, otherwise set it to FALSE.

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


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralError: WINDOWS.H already included! Pin
getitforfun18-Sep-03 10:39
getitforfun18-Sep-03 10:39 
GeneralAvoid multiple definitions of winsock structs in MFC applications Pin
Jon Skaranger29-Jun-03 11:23
sussJon Skaranger29-Jun-03 11:23 
GeneralRe: Avoid multiple definitions of winsock structs in MFC applications Pin
Jon Skaranger29-Jun-03 11:29
sussJon Skaranger29-Jun-03 11:29 
GeneralI' m not able to use this class because of MFC Pin
Sharkky23-Mar-03 23:41
Sharkky23-Mar-03 23:41 
GeneralRe: I' m not able to use this class because of MFC Pin
HippoTas13-Apr-03 21:09
HippoTas13-Apr-03 21:09 
GeneralRe: I' m not able to use this class because of MFC Pin
HippoTas13-Apr-03 23:02
HippoTas13-Apr-03 23:02 
GeneralNM Very good! THX, it saved me much time! Pin
Thomas Latuske7-Mar-03 11:03
Thomas Latuske7-Mar-03 11:03 
GeneralComments Pin
Anatoly Ivasyuk21-Jan-03 6:08
Anatoly Ivasyuk21-Jan-03 6:08 
Good class, but I have a couple of comments.

- Pop3.cpp should not #include Pop3Monitor.h

- MFC dependencies (CStringList and CString) don't quite make it usable under plain Win32, not to mention ATL and WTL. I noticed you have USE_CSTRING, but the method definitions don't use it. WTL includes CString and CStringList can be faked, but maybe it would be better to substitute STL collections?

Thanks!
-Anatoly

Anatoly Ivasyuk is co-founder of DTLink Software, a company specializing in Internet software and technologies. He is the author of DTLink's Windows products: AnswerTool, FAQTool, AppUpdate, and Personal Stock Monitor
Questionhow about file attachments ? Pin
xuxiaofeng6-Jan-03 16:14
xuxiaofeng6-Jan-03 16:14 
AnswerRe: how about file attachments ? Pin
100311036-Jan-03 18:55
100311036-Jan-03 18:55 
GeneralRe: how about file attachments ? Pin
xuxiaofeng12-Jun-03 15:12
xuxiaofeng12-Jun-03 15:12 
GeneralServer please Pin
venu_pro9-Apr-04 3:55
sussvenu_pro9-Apr-04 3:55 
AnswerRe: how about file attachments ? Pin
HippoTas12-Jun-03 1:51
HippoTas12-Jun-03 1:51 
GeneralRe: how about file attachments ? Pin
xuxiaofeng12-Jun-03 15:11
xuxiaofeng12-Jun-03 15:11 
GeneralRe: how about file attachments ? Pin
Gajalakshmi Krishnan11-Apr-05 5:52
Gajalakshmi Krishnan11-Apr-05 5:52 
GeneralA request Pin
Gisle Vanem4-Jan-03 22:54
Gisle Vanem4-Jan-03 22:54 
GeneralRe: A request Pin
100311035-Jan-03 20:15
100311035-Jan-03 20:15 
Generalsaving server and user name info Pin
Marc Clifton4-Jan-03 11:24
mvaMarc Clifton4-Jan-03 11:24 

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.