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






3.48/5 (21 votes)
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.