Click here to Skip to main content
Click here to Skip to main content

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

By , 17 Nov 2002
 

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Karavaev Denis
Systems Engineer
Russian Federation Russian Federation
Member
Now in Moscow.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberreldridge10 Feb '12 - 10:49 
Very good code, and easy to use.
GeneralGreat JobmemberLokesh_193744414 Sep '10 - 17:46 
Great job done. Friend i am looking for getting attachments and save to a particular location could you help me please.
 
Thanks,
Regards,
Lokesh Kumar Dwivedi
ee

GeneralCan't run with Gmailmemberanki1236 Jul '09 - 22:51 
Hi all,
 
I m able to run this library with yahoo account but it
can not work with Gmail account.
 
for pop3 server I m using -- pop.gmail.com
& Port - 995 or 110
 
but it can't work.
 
Plz help me
 
Thanks in advance
GeneralRe: Can't run with Gmailmember1234anand31 Aug '09 - 23:13 
Try to use ssl
GeneralGmail AccountmemberAriel Piñeiro26 Jun '09 - 7:14 
The library works with Gmail Account?
 
I cant't run with gmail.
Generalnice class...memberlamarez28 Dec '08 - 12:10 
If this class does not work, look at http://forum.cbsystematics.com/showthread.cbsx?goto=newpost&t=119
 
lamarez iz da ril pocan

Generalits saying -ERR System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it. plz helpmemberMember 27193538 Dec '08 - 9:07 
following is the complete error im getting:
 
-ERR System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
at Mail.MailPOP3.DoConnect(String pop3host, Int32 port, String user, String pwd) in C:\Downloads\MailTest\MailTest\MailPOP3.cs:line 114
GeneralGetTop is not a function in Mesaage Class.memberanjani_jan194 Jul '08 - 0:46 
GetTop is not a function in Mesaage Class.So ,it gives an error.
 
Anju
GeneralRe: GetTop is not a function in Mesaage Class.memberJackieHoffman18 Nov '08 - 14:09 
No, it's a method in the waspPOP3 class.
Generalhelp !!!!!!!!!!!!!!!!memberHorra1 Mar '08 - 8:31 
i'm gettin dis error plz help me out
 

-ERR System.NullReferenceException: Object reference not set to an instance of an object.
at Mail.MailPOP3.DoConnect(String pop3host, Int32 port, String user, String pwd) in c:\Documents and Settings\Administrator\Desktop\MailTest\MailTest\MailPOP3.cs:line 120

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 18 Nov 2002
Article Copyright 2002 by Karavaev Denis
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid