Click here to Skip to main content
15,890,438 members
Articles / Programming Languages / C#
Article

Using POP3 with C# to download and parse your mail.

Rate me:
Please Sign up or sign in to vote.
3.48/5 (21 votes)
17 Nov 2002CPOL 230K   13.1K   84   37
Using this class in your C# application you can manage your mailbox and download and parse your messages.

Introduction

This article explains a simple way to add mail support in your application. Just use the classes:

POP3class methods:

  • C#
    string DoConnect(String pop3host,int port, String user, String 
    pwd)
  • string GetStat()
  • string GetList()
  • string GetList(int num)
  • string Retr(int num)
  • string Dele(int num)
  • string Rset()
  • string Quit()
  • string GetTop(int num)
  • string GetTop(int num_mess, int num_lines)
  • string GetUidl()
  • string GetUidl(int num)
  • string GetNoop()

MessageClass methods:

  • string GetFrom(string messTop)
  • string GetDate(string messTop)
  • string GetMessID(string messTop)
  • string GetTo(string messTop)
  • string GetSubject(string messTop)
  • string GetBody(string AllMessage)

Using the code

The following sample illustrates how to use the classes:

C#
POP3class pop3;
pop3 = new POP3class();
pop3.DoConnect("your.mail.server",110,"username","password");
pop3.GetStat();
// and if we have mail:
MessageClass msg;
msg = new MessageClass();
string sMessageTop = msg.GetTop(1);
//OK, message is well, lets download it.
string sAllMessage = msg.Retr(1);
msg.GetBody(sAllMessage);

That's all.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems Engineer
Russian Federation Russian Federation
Now in Moscow.

Comments and Discussions

 
GeneralRe: I can not seem to get the email headers, etc Pin
JackieHoffman18-Nov-08 14:14
JackieHoffman18-Nov-08 14:14 
GeneralWhy I can't get the infomations of my emails, such as sender, subject and date. Pin
renchao27-Apr-03 8:25
renchao27-Apr-03 8:25 
GeneralGood Job Pin
John O'Byrne3-Jan-03 0:37
John O'Byrne3-Jan-03 0:37 
GeneralThis code does not handle characters outside the ASCII Pin
OceanSide5-Dec-02 8:06
OceanSide5-Dec-02 8:06 
GeneralRe: This code does not handle characters outside the ASCII Pin
vietnc26-Dec-06 16:25
vietnc26-Dec-06 16:25 
Generalno attachment! Pin
Anonymous22-Nov-02 21:53
Anonymous22-Nov-02 21:53 
GeneralSome errors has been fixed. Thanks 2 Bruno Podetti (-) Pin
Karavaev Denis18-Nov-02 4:08
Karavaev Denis18-Nov-02 4:08 
General-ERR Wrong State Pin
aryehof12-Nov-02 2:42
aryehof12-Nov-02 2:42 
GeneralRe: -ERR Wrong State Pin
aryehof12-Nov-02 13:17
aryehof12-Nov-02 13:17 
GeneralGreat article Pin
Dewdman428-Nov-02 21:11
Dewdman428-Nov-02 21:11 
GeneralRe: Great article Pin
Stoyan Damov8-Mar-03 18:35
Stoyan Damov8-Mar-03 18:35 

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.