Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
17 Nov 2002 1  
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:

  • 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:

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 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