Click here to Skip to main content
12,450,089 members (42,822 online)
Click here to Skip to main content
Add your own
alternative version

Stats

190.9K views
12K downloads
83 bookmarked
Posted

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

, 17 Nov 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionGood News !! Visual Studio now has support for POP3, SMTP, IMAP, etc Pin
Tino Fourie21-Feb-14 9:59
memberTino Fourie21-Feb-14 9:59 
Questionmsg.GetTop() Pin
brob199013-Nov-13 14:15
memberbrob199013-Nov-13 14:15 
GeneralMy vote of 5 Pin
Amir Mohammad Nasrollahi29-Jul-13 21:49
professionalAmir Mohammad Nasrollahi29-Jul-13 21:49 
GeneralMy vote of 5 Pin
reldridge10-Feb-12 10:49
memberreldridge10-Feb-12 10:49 
GeneralGreat Job Pin
Lokesh_193744414-Sep-10 17:46
memberLokesh_193744414-Sep-10 17:46 
GeneralCan't run with Gmail Pin
anki1236-Jul-09 22:51
memberanki1236-Jul-09 22:51 
GeneralRe: Can't run with Gmail Pin
1234anand31-Aug-09 23:13
member1234anand31-Aug-09 23:13 
GeneralGmail Account Pin
Ariel Piñeiro26-Jun-09 7:14
memberAriel Piñeiro26-Jun-09 7:14 
Generalnice class... Pin
lamarez28-Dec-08 12:10
memberlamarez28-Dec-08 12:10 
Generalits saying -ERR System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it. plz help Pin
Member 27193538-Dec-08 9:07
memberMember 27193538-Dec-08 9:07 
GeneralGetTop is not a function in Mesaage Class. Pin
anjani_jan194-Jul-08 0:46
memberanjani_jan194-Jul-08 0:46 
GeneralRe: GetTop is not a function in Mesaage Class. Pin
JackieHoffman18-Nov-08 14:09
memberJackieHoffman18-Nov-08 14:09 
Generalhelp !!!!!!!!!!!!!!!! Pin
Horra1-Mar-08 8:31
memberHorra1-Mar-08 8:31 
GeneralIam getting this error Input string was not in a correct format And login is ok but iam not getting the mails ..plz help me Pin
anjaneya75-Feb-08 0:57
memberanjaneya75-Feb-08 0:57 
GeneralHelp me!!! Pin
saobangtn2231-Aug-07 17:15
membersaobangtn2231-Aug-07 17:15 
GeneralRe: Help me!!! Pin
he2he29-Oct-07 4:23
memberhe2he29-Oct-07 4:23 
GeneralSTD3 violation Pin
mastdk21-Sep-06 3:36
membermastdk21-Sep-06 3:36 
GeneralNice one Pin
Gav_Roberts2k511-Oct-05 21:56
memberGav_Roberts2k511-Oct-05 21:56 
GeneralSSL Support Pin
Nihal Chand10-Oct-05 19:06
memberNihal Chand10-Oct-05 19:06 
GeneralRe: SSL Support Pin
novice__geek14-Mar-09 19:04
membernovice__geek14-Mar-09 19:04 
GeneralError in GetMail (MailPOP3.cs) Pin
Memot7-Jul-04 4:40
memberMemot7-Jul-04 4:40 
QuestionThere is the function GetBody? Pin
Albert Pascual6-Aug-03 5:06
memberAlbert Pascual6-Aug-03 5:06 
Generali can't it Pin
oeurun6-Aug-03 2:11
memberoeurun6-Aug-03 2:11 
GeneralI can not seem to get the email headers, etc Pin
Jediman6-Jul-03 14:24
memberJediman6-Jul-03 14:24 
GeneralRe: I can not seem to get the email headers, etc Pin
JackieHoffman18-Nov-08 14:14
memberJackieHoffman18-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
memberrenchao27-Apr-03 8:25 
GeneralGood Job Pin
John O'Byrne3-Jan-03 0:37
memberJohn O'Byrne3-Jan-03 0:37 
GeneralThis code does not handle characters outside the ASCII Pin
OceanSide5-Dec-02 8:06
memberOceanSide5-Dec-02 8:06 
GeneralRe: This code does not handle characters outside the ASCII Pin
lesnikowski6-Nov-05 13:05
memberlesnikowski6-Nov-05 13:05 
GeneralRe: This code does not handle characters outside the ASCII Pin
vietnc26-Dec-06 16:25
membervietnc26-Dec-06 16:25 
Generalno attachment! Pin
Anonymous22-Nov-02 21:53
sussAnonymous22-Nov-02 21:53 
GeneralSome errors has been fixed. Thanks 2 Bruno Podetti (-) Pin
Karavaev Denis18-Nov-02 4:08
memberKaravaev Denis18-Nov-02 4:08 
General-ERR Wrong State Pin
AlexH12-Nov-02 2:42
memberAlexH12-Nov-02 2:42 
GeneralRe: -ERR Wrong State Pin
AlexH12-Nov-02 13:17
memberAlexH12-Nov-02 13:17 
GeneralGreat article Pin
Dewdman428-Nov-02 21:11
memberDewdman428-Nov-02 21:11 
GeneralRe: Great article Pin
Stoyan Damov8-Mar-03 18:35
sussStoyan 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.

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