Click here to Skip to main content
Email Password   helpLost your password?

Introduction

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

POP3class methods:

MessageClass methods:

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.

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralCan't run with Gmail
anki123
23:51 6 Jul '09  
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 Gmail
1234anand
0:13 1 Sep '09  
Try to use ssl
GeneralGmail Account
Ariel Piñeiro
8:14 26 Jun '09  
The library works with Gmail Account?

I cant't run with gmail.
Generalnice class...
lamarez
13:10 28 Dec '08  
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 help
Member 2719353
10:07 8 Dec '08  
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.
anjani_jan19
1:46 4 Jul '08  
GetTop is not a function in Mesaage Class.So ,it gives an error.

Anju
GeneralRe: GetTop is not a function in Mesaage Class.
JackieHoffman
15:09 18 Nov '08  
No, it's a method in the waspPOP3 class.
Generalhelp !!!!!!!!!!!!!!!!
Horra
9:31 1 Mar '08  
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
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
anjaneya7
1:57 5 Feb '08  
MailHeader[] myHeader = pop3Connection.GetMails(false);

if(myHeader!=null)
{
listView1.Items.Clear();

for(int n=0;n<myHeader.Length;n++)
{
if(myHeader[n]!=null)
{
ListViewItem lvItem = listView1.Items.Add(myHeader[n].from);
lvItem.SubItems.Add(myHeader[n].to);
lvItem.SubItems.Add(myHeader[n].date);
lvItem.SubItems.Add(myHeader[n].subject);

Mailpop3.cs page
int count = int.Parse(listHeader[1]);
GeneralHelp me!!!
saobangtn22
18:15 31 Aug '07  
What is wrong with the code for that area:
in function is:public MailHeader[] GetMails(bool body){}
it i error in line: int count = int.Parse(listHeader[1]);
Can you help me,please?


Thanks
GeneralRe: Help me!!!
he2he
5:23 29 Oct '07  
Same here

list = "+OK\r\n1 3475\r\n2 3503\r\n"

param has 4 dimensions
than it's tried to split param[0] (param[0].Split(' ')) which is just "+OK\r" in my case and so listHeader has just one diemension and is "+OK\r", too.

Than the code trys to access listHeader[1] which isn't possible, as listHeader has just one dimension.
GeneralSTD3 violation
mastdk
4:36 21 Sep '06  
Some mail clients like courier sends this:

+OK POP3 clients that break here, they violate STD53

and it casues program to crash

Martin
GeneralNice one
Gav_Roberts2k5
22:56 11 Oct '05  
I've not been able to successfully test this, but looking at the source code and looking at mine, this could be onto a winner.

Although I could be rather Mad about this as I have just spent at least 40 working hours creating multiple regex strings etc to pull apart my message. I think I may test yours further to see whether it handles my messages better.

Also, do you intend to add attachment support?

Gav
GeneralSSL Support
Nihal Chand
20:06 10 Oct '05  
Hi Dear,
It is really a nice work. Do anybody have an idea of adding SSL support.

Nihal Chand
+91 9872220250
GeneralRe: SSL Support
novice__geek
20:04 14 Mar '09  
Check this primitive but functional library... http://code.google.com/p/pop3ssl[^]

It is fairly simple and easy to use and also easy to customize
GeneralError in GetMail (MailPOP3.cs)
Memot
5:40 7 Jul '04  
On line 493 there is this sendcommand:
sTemp = SendCommand("TOP " + num + "\r\n");

which causes an error (it's not a valid top command!). The following code does not give this error:

sTemp = SendCommand("TOP " + num + " " + 1 + "\r\n");

This explains why several people (including me) didn't get anything to see in the listView1 (from, to, date and subject fields).
GeneralThere is the function GetBody?
Albert Pascual
6:06 6 Aug '03  
I have download your sample, however there is no GetBody in that sample on the MailMessage class as you said in the article. I thought you wanted to know.

Albert
Generali can't it
oeurun
3:11 6 Aug '03  
i try using this class and sample project but i don't read any mail...
please help me
GeneralI can not seem to get the email headers, etc
Jediman
15:24 6 Jul '03  
What is wrong with the code for that area
MailHeader[] myHeader = pop3Connection.GetMails(false);


if(myHeader!=null)
{
listView1.Items.Clear();
for(int n = 0; n {
if(myHeader[n]!=null)
{
ListViewItem lvItem = listView1.Items.Add(myHeader[n].from);
lvItem.SubItems.Add(myHeader[n].to);
lvItem.SubItems.Add(myHeader[n].date);
lvItem.SubItems.Add(myHeader[n].subject);


it wont display the email info such as the from,to, or any of those fields!
Has anyone gotten it to work?
GeneralRe: I can not seem to get the email headers, etc
JackieHoffman
15:14 18 Nov '08  
You have to first use the method waspMessage.Retr(x) to get the message, then get parts of it by passing in the whole message string, like so: (I converted to vb)

Dim sAllMessage As String = myPop3.Retr(1)
dim bodyPart as string = myPop3.GetBody(sAllMessage)
dim toPart as string = myPop3.GetTo(sAllMessage)
dim fromPart as string = myPop3.GetFrom(sAllMessage)

etc.

This seems to work.
GeneralWhy I can't get the infomations of my emails, such as sender, subject and date.
renchao
9:25 27 Apr '03  
I can connect the POP3 server correctly, but I can't get the infomations of my emails, such as sender, subject and date.

Why?

Thank you for your code.

Renchao
GeneralGood Job
John O'Byrne
1:37 3 Jan '03  
Well commented source code, and great class
You've got my 5
GeneralThis code does not handle characters outside the ASCII
OceanSide
9:06 5 Dec '02  
in the code, it is using:
streamReader = new StreamReader(tcpClient.GetStream());

that means characters like "áéíóú¿ñ" will lost.

Yes, the code also does not mention anything with attachment with it BIG part of any email system.

It will be idea if Mr. Karavaev Denis can make those two things work.

BTW, once you try to handle the special characters like "áéíóú¿ñ", you have to use UTF7 for the streamReader. But that will kill all your attachment encoding.

Does anyone here have a solution?

--OceansideConfused
GeneralRe: This code does not handle characters outside the ASCII
lesnikowski
14:05 6 Nov '05  
It may be usefull to someone: http://www.lesnikowski.com/mail[^]
GeneralRe: This code does not handle characters outside the ASCII
vietnc
17:25 26 Dec '06  
i hope this article can help you
http://www.codeproject.com/useritems/Pop3MimeClient.asp


Last Updated 18 Nov 2002 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010