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

Simple POP3 Email Class

By , 13 Mar 2007
 
Screenshot - ScreenShot.jpg

Introduction

This is a simple class written in VB.NET that allows you to download email from a POP3 mail server. It includes functions for extracting who the mail is for, who it is from, the subject, and the email body. As it stands, there is no support for handling attachments.

Background

When I started to work with the .NET framework, one of the first things I noticed was its lack of support for downloading emails from a mail server. There is very good support for sending mail via the SMTP protocol, but nothing for receiving. The class came about when I needed a way of retrieving log files that were sent as emails and acting on the information contained in the mail.

Using the code

There are two main classes you can use. The first one is called POP3, and is used to connect to the POP3 server and deal with all commands you have to issue in order to retrieve mail. The second class is called EmailMessage, and is used to extract all the different sections out of messages.

You declare the variables and create the objects, like so:

Dim popConn As SamplePop3Class.POP3
Dim mailMess As SamplePop3Class.EmailMessage

'create the objects

popConn = New SamplePop3Class.POP3
mailMess = New SamplePop3Class.EmailMessage

Once you have created the objects, connect to the mail server and find out how many messages (if any) are on the server.

'if we have got to this point, try and connect to the server

popConn.POPConnect(strMailServeor, strUsername, strPassword)

'now we have a connection, see if there are any mails on the server

intMessCnt = popConn.GetMailStat()

Now, the variable intMessCnt will contain how many messages are on the server. If it is greater then 0, loop through each of the messages and extract the sections of the email.

'if we returned some messages, loop through each one and get the details

For i = 1 To intMessCnt

    'load the entire content of the mail into a string

    strMailContent = popConn.GetMailMessage(i)

    'call the functions to get the various parts out of the email 

    strFrom = mailMess.ParseEmail(strMailContent, "From:")
    strSubject = mailMess.ParseEmail(strMailContent, "Subject:")
    strToo = mailMess.ParseEmail(strMailContent, "To:")
    strBody = mailMess.ParseBody()

next i

Now, you should have all the sections of the email held in your variables. From here, you could save the email to an external file, insert the details into a database, or do whatever you want with the information.

Points of interest

This was the first time I have ever tried to write an application that involved communicating over TCP/IP. I was very surprised how easy and powerful it is, the hardest part was making sure I handled any errors coming back from the POP3 server correctly, but as everything coming back into an IOStream, it was very easy to read.

The only problem with this code as it stands is its lack of support for attachments. I have looked into it and it does seam very complex, but I am going to have a go at it and will update this code once I have it working.

Please note this is my first posting, so if anyone has any pointers on how to improve my article, let me know!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Luke Niland

United Kingdom United Kingdom
I currently work at for a newspaper group in Lancashire(U.K) in the IT dept. I deal with a quite a few different IT system on a day to day basis. My programming experience includes vb6, asp.net, sql and some C++. Check my blog out at beakersoft.co.uk.
 
I have also recently started writing software with a couple of guys i work with, check out our website at www.we3soft.com

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 5memberMadness Fading21-May-13 17:40 
Plain and Simple. To the point. Easy to understand. Nice Job.
SuggestionThis is cool but I found more...memberscarterszoo9-Oct-12 17:05 
Luke,
 
Excellent work and I enjoy your blog.
 
For those of you who were looking for more, check out...
 
David Goben's Blog on Slideshare.net[^]
 
I haven't read it all but it looks interesting. Cool | :cool:
GeneralMy vote of 5memberEricoCanales11-Sep-12 12:17 
Good information. Thanks !
QuestionDo you have it in C#?membereveniza30-Jul-12 18:09 
Hi,
wondering if you have this codes in C#. Could you attached it here?
It will be much appreciate if you have it..
Questionhey luke need help urgentlymemberakash89838-Apr-12 18:58 
i got an error
A connection attept failed because the connected party did not properly respond after a period of time, or established connection failed bcoz connected has failed to respond 173.194.79.108:110
plz hhelp me soon
Questioni got this errormemberzhtway8-Aug-11 12:56 
I got this...
 
pop3 error unexpected response from mail server getting email body - err invalid command...
 
I don't know what to do..
 
Thanks
AnswerRe: i got this errormemberMember 794829920-Feb-12 8:10 
I had the same error and was able to fix it by calling the RETR command directly instead of using the SendData function. Replace the GetMailMessage function with this:
 
    Public Function GetMailMessage(ByVal intNum As Integer) As String
        Dim strTemp As String
        Dim strEmailMess As String = ""
        Try
            Dim strRetr As String = "RETR " & intNum
            Dim outBuff As Byte()
            outBuff = ConvertStringToByteArray(strRetr & vbCrLf)
            POP3Stream.Write(outBuff, 0, strRetr.Length + 2)
            If WaitFor("+OK") = False Then
                POPErrors("Unexpected Response from mail server getting email body" & vbNewLine & strDataIn)
                GetMailMessage = ("No Email was Retrived")
                Exit Function
            End If
            strTemp = inStream.ReadLine
            While (strTemp <> ".")
                strEmailMess = strEmailMess & strTemp & vbCrLf
                strTemp = inStream.ReadLine
            End While
            GetMailMessage = strEmailMess
        Catch ex As Exception
            GetMailMessage = "No Email was Retrived"
        End Try
    End Function

QuestionCan someone give me a sample for hotmail???memberSteef43525-Jul-11 0:58 
Can somebody tell me what I must do if I want to get mail from the hotmail server. I already set the port to 995, but when I try to connect it says:
 
Unable to read data from the transport connection: [here comes a translated message, my os is dutch] The external host disconnected.
 
How do I get this working??? Or are the mails encrypted, so the program just can't read it?
 
Thanks!
 
Steef
AnswerRe: Can someone give me a sample for hotmail???memberLuke Niland25-Jul-11 9:40 
Hi,
 
If you look at http://lifehacker.com/5169684/hotmail-finally-enables-pop3-worldwide[^] you can see connecting to hotmail over pop3 requires an ssl connection, something this example does not support.
 
As quite a few people have asked for this if i get time over the next couple of weeks i might see whats involved to update this article to include ssl support

Generalbase64 decodingmemberRamsin1-Jul-09 11:13 
Hello Luke,
 
I'm interested in your code so I was reviewing but then I ran into one issue and will appreciate it if you give me some help on it. Most of the time I get an error as "A Problem occurred while decoding a base64 email".
 
Any solution to this problem?
 
Thanks!
 
Thanks for reading my aticle

GeneralRe: base64 decodingmemberLuke Niland9-Jul-09 8:06 
Hi Ramsin,
 
Its probably hitting an attachment, i would imagine that what's causing the error
 
Cheers
Luke
 

GeneralRe: base64 decodinggroupjseph8816-Jan-13 16:04 
Hi,

Have u fix the problem that occurs decoding base 64 email?

I got that error, when an email has attachment(s). And this is the error:
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.

Anyway, can you let me know how to retrieve attachment(s) using that code.

Thank you.
GeneralSSL/Pop3 Support in this DemomemberLuke Niland30-Mar-09 9:50 
Quite a few people have asked if this demo supports pop3 over ssl, in its current state the answer to this question is no, so if you are trying to download of gmail or anything over port 995 (the normal secure pop3 port) its not going to work.
 
I've had a quick look around and found an open project at http://www.mentalis.org/soft/projects/ssocket/
 
Look like it should be possible to mod this demo (or create a new one) using this library to add ssl support. If anyone does it let me know and ill post a link here to it, or when i get round to it i'll have a go
 

GeneralA problem occured while decoding a base64 email.memberYueming Wu22-Feb-09 1:44 
When the content of email is not English but the Chinese, it prompt the following error:
 
A problem occured while decoding a base64 email.
 
Do you have any idea to fix this issue? Thanks in advanced.
 
Yueming Wu

GeneralRe: A problem occured while decoding a base64 email.memberLuke Niland22-Feb-09 5:28 
Hi,
 
Its probably having trouble with the character set. If you forward me the email i will take a look
 
Cheers
Luke
 
beakersoft.co.uk

GeneralRe: A problem occured while decoding a base64 email.memberYueming Wu22-Feb-09 15:39 
Thanks for your reply,
 
I checked it more after I asked that question. It does not the trouble with the character set. The error occuried when there is a picture embeded in the email. I believe you are finding the way to fix this now. If you still want me to send you that email, please let us know. The problem is that I can not find your email address.
 
Thanks again for your help.
 
Yueming Wu

GeneralRe: A problem occured while decoding a base64 email.memberLuke Niland23-Feb-09 8:12 
forward me the email to luke@beakersoft.wanadoo.co.uk and ill have a look
 

QuestionRe: A problem occured while decoding a base64 email.groupjseph8816-Jan-13 16:02 
Hi,
 
Have u fix the problem that occurs decoding base 64 email?
 
I got that error, when an email has attachment(s). And this is the error:
The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters.
 
Anyway, can you let me know how to retrieve attachment(s) using that code.
 
Thank you.
QuestionIt's not working with GMAIL. Can anyone help me? It could be a SSL problem?memberitamar.locatelli@gmail.com28-Jan-09 3:19 
Someone uses this with gmail?
AnswerRe: It's not working with GMAIL. Can anyone help me? It could be a SSL problem?memberLuke Niland2-Feb-09 8:23 
Hi,
 
i cant see it being an ssl problem, ssl is used over http, not pop3. Make sure your gmail account is configured for access with pop3, check out http://mail.google.com/support/bin/answer.py?hl=en&answer=13273 on how to do it, and let us know how you get on
 
Cheers
Luke
 
beakersoft.co.uk

GeneralRe: It's not working with GMAIL. Can anyone help me? It could be a SSL problem?memberw3rm24-Mar-09 6:08 
hi,
 
i cant access pop.gmail.com ...
 
in this link, they say that the port is 995
http://mail.google.com/support/bin/answer.py?answer=13287[^]
 
i changed your program in line 24
to connect to port 995
 
TCP.Connect(strServer, 995)
 
and the application show me an error message...
 
POP3ERROR -
Unexpected response from mail server when connecting...
 
thanks
GeneralRe: It's not working with GMAIL. Can anyone help me? It could be a SSL problem?memberLuke Niland25-Mar-09 7:41 
i think the data is probably coming back encrypted, and as it stands this demo wont deal with that (it would explain why your getting an unknown response). I have a look this week and try and confirm what is happening.
 

GeneralRe: It's not working with GMAIL. Can anyone help me? It could be a SSL problem?membercstrader23227-Mar-09 2:54 
I've been using this super app for awhile, but I think it does not work with SSL. Can you confirm? Any other alternatives?
 
Thanks
QuestionHow to read attachment's content from emailmemberbalamurugan kalyanasundaram1-Sep-08 3:40 
Please help me soon
AnswerRe: How to read attachment's content from emailmemberLuke Niland7-Sep-08 1:32 
As mentioned in a previous message, adding support for attachments is very difficult. Is anyone is willing to help me write/debug it we can give it a go, i dont have enough time to tackle this on my own at present
 
Cheers
Luke
 
beakersoft.co.uk

QuestionQuestion on Message bodymembertnyatsvimbo@yahoo.com10-Aug-08 23:19 
How do i get rid of this part:
 
This is a multi-part message in MIME format.
 
--_bff0947c-7186-4598-9d02-f9df9c7b0372_
Content-Type: text/plain;charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

 
since it makes retrieving the data out difficult.
 
Tinei Nyatsvimbo

AnswerRe: Question on Message bodymemberLuke Niland13-Aug-08 11:39 
Hi,
 
At what point are you seeing that string, is it at the start of the email body?
 

GeneralRe: Question on Message bodymembertnyatsvimbo@yahoo.com13-Aug-08 22:05 
Hi Luke,
 
The text is coming out at the beginning of the message and there is also some at the end of the message. I noticed now that it is as a result of the message being send as HTML from public domains like gmail which seem to add on that text. My problem with that is my data contained in the email will have excess details that i don't want to import into the database. Can this be stripped out?
 
Cheers & Thanks,
Tinei
 
Tinei Nyatsvimbo

GeneralRe: Question on Message bodymemberLuke Niland14-Aug-08 6:40 
You will be able to strip it out, its just a case of working out where the string starts and ends. If you forward me a couple of example emails ill have a look to see what the rfc's say about it, and try and come up with something
 
Cheers
Luke
 
beakersoft.co.uk

GeneralHere is a samplemembertnyatsvimbo@yahoo.com15-Aug-08 1:54 
This is a multi-part message in MIME format.
 
------=_NextPart_000_0004_01C8FEDD.61546ED0
Content-Type: text/plain;charset="us-ascii"
Content-Transfer-Encoding: 7bit
 
'KSN001', '0', '', '', 0 , 0 , '', '', '', '', 0 , 'BAG', #09/Aug/2008
17:02:43#, 'BAG', 'WYVERNE', '', False , 'KSN00102D', 1 , '0006', 'COPPER
CONCENTRATE', '', '2510006', 'KSN00102D', 1198.4 , , '', '', '', '', '', '',
'', '', '', '', ' 'KSN001', '0', '', '', 0 , 0 , '', '', '', '', 0 , 'BAG',
#09/Aug/2008 17:03:10#, 'BAG', 'WYVERNE', '', False , 'KSN00102C', 1 ,
'0007', 'COPPER CONCENTRATE', '', '2510007', 'KSN00102C', 1198.4 , , '', '',
'', '', '', '', '', '', '', '', ' 'KSN001', '0', '', '', 0 , 0 , '', '', '',
'', 0 , 'BAG', #09/Aug/2008 17:03:39#, 'BAG', 'WYVERNE', '', False ,
'KSN00102B', 1 , '0008', 'COPPER CONCENTRATE', '', '2510008', 'KSN00102B',
1198.4 , , '', '', '', '', '', '', '', '', '', '', ' 'KSN001', '0', '', '',
0 , 0 , '', '', '', '', 0 , 'BAG', #09/Aug/2008 17:03:58#, 'BAG', 'WYVERNE',
'', False , 'KSN00102A', 1 , '0009', 'COPPER CONCENTRATE', '', '2510009',
'KSN00102A', 1198.4 , , '', '', '', '', '', '', '', '', '', '', ' 'KSN001',
'0', '', '', 0 , 0 , '', '', '', '', 0 , 'BAG', #09/Aug/2008 17:04:17#,
'BAG', 'WYVERNE', '', False , 'KSN001029', 1 , '0010', 'COPPER CONCENTRATE',
'', '2510010', 'KSN001029', 1198.4 , , '', '', '', '', '', '', '', '', '',
'', ' 'KSN001', '0', '', '', 0 , 0 , '', '', '', '', 0 , 'BAG', #09/Aug/2008
17:06:10#, 'BAG', 'WYVERNE', '', False , 'KSN001028', 1 , '0011', 'COPPER
CONCENTRATE', '', '2510011', 'KSN001028', 1198.4 , , '', '', '', '', '', '',
'', '', '', '', ' 'KSN001', '0', '', '', 0 , 0 , '', '', '', '', 0 , 'BAG',
#09/Aug/2008 17:06:28#, 'BAG', 'WYVERNE', '', False , 'KSN001027', 1 ,
'0012', 'COPPER CONCENTRATE', '', '2510012', 'KSN001027', 1198.4 , , '', '',
'', '', '', '', '', '', '', '', ' 'KSN001', '0', '', '', 0 , 0 , '', '', '',
'', 0 , 'BAG', #09/Aug/2008 17:06:44#, 'BAG', 'WYVERNE', '', False ,
'KSN001026', 1 , '0013', 'COPPER CONCENTRATE', '', '2510013', 'KSN001026',
1198.4 , , '', '', '', '', '', '', '', '', '', '', ' 'KSN001', '0', '', '',
0 , 0 , '', '', '', '', 0 , 'BAG', #09/Aug/2008 17:07:06#, 'BAG', 'WYVERNE',
'', False , 'KSN001025', 1 , '0014', 'COPPER CONCENTRATE', '', '2510014',
'KSN001025', 1198.4 , , '', '', '', '', '', '', '', '', '', '', ' 'KSN001',
'0', '', '', 0 , 0 , '', '', '', '', 0 , 'BAG', #09/Aug/2008 17:07:26#,
'BAG', 'WYVERNE', '', False , 'KSN001024', 1 , '0015', 'COPPER CONCENTRATE',
'', '2510015', 'KSN001024', 1198.4 , , '', '', '', '', '', '', '', '', '',
'', '
 

 

------=_NextPart_000_0004_01C8FEDD.61546ED0
Content-Type: text/html;charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
 
<html xmlns:v="3D"urn:schemas-microsoft-com:vml"" mode="hold" />xmlnsBlush | :O =3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">
 
<head>
<meta http-equiv="3DContent-Type" content="3D"text/html;" mode="hold" />charset=3Dus-ascii">
<meta name="3DGenerator" content="3D"Microsoft" word="" 11="" hold=" /><style><br mode=" times="" new="" roman=";}<br mode=" edit=" spidmax=3D" 1026=" /><br mode=" 1=" /><br mode=">
Tinei Nyatsvimbo
</meta></head>
GeneralRe: Here is a samplememberLuke Niland25-Aug-08 12:36 
Hi Tinei,
 
Try replacing the ParseBody function with this one:
 
  Public Function ParseBody() As String
 
        'To get the body, everything after the first null line of the message is it (rfc822)
        Dim strTmp As String
        Dim intLenToStart, intLenToend As Integer
 
        'set the temp var to the message body by getting everything after the null line
        strTmp = m_MessageSource.Substring(m_MessageSource.IndexOf(vbCrLf + vbCrLf))
 
        'get the encoding of the message out, that way we know if we have to run it through the base64 decode
        'routine or not
        If InStr(m_MessageSource, "Content-Transfer-Encoding: base64") Then
            'call the decode routine
            strTmp = DecodeBase64(strTmp)
        End If
 
        'try and extract the plain text out of the email body
        intLenToStart = InStr(strTmp, "Content-Type: text/plain")
        strTmp = strTmp.Substring(intLenToStart, Len(strTmp) - intLenToStart)
 
        'now find the first two new lines, this should be where the text starts
        intLenToStart = InStr(strTmp, Chr(13) & Chr(10) & Chr(13) & Chr(10))
        strTmp = strTmp.Substring(intLenToStart, Len(strTmp) - intLenToStart)
 
        'find the end of the string, should be indicated by two more line ends and -------=_ Miuns another 2 places to get rid of
        'the trailing 0D 0A
        intLenToend = InStr(strTmp, Chr(13) & Chr(10) & Chr(13) & Chr(10) & "------=_") - 2
        strTmp = strTmp.Substring(3, intLenToend)
 
        'Strip out the odd hex that apears at the start and the end
        strTmp = Replace(strTmp, Chr(10) & Chr(9), "")
        strTmp = Replace(strTmp, Chr(13), "")
 
        ParseBody = Trim(strTmp)
 
    End Function
 
I think it should do what you want, but i'm not sure if it will cope with emails that dont contain a html part.
 
Let me know how you get one
 
Cheers
Luke
 
beakersoft.co.uk

GeneralThanksmembertnyatsvimbo@yahoo.com25-Aug-08 20:16 
Will try it out and let you know.
 
Cheers,
Tinei
 
Tinei Nyatsvimbo

GeneralRe: ThanksmemberLuke Niland7-Sep-08 1:28 
Hi Tinei, did this work?
 
Cheers
Luke
 
beakersoft.co.uk

GeneralFeedbackmembertnyatsvimbo@yahoo.com7-Sep-08 4:21 
i decided to trim the message in the database. haven't had time to test your solution. will do so this week and let you know.
 
Thanks a lot
 
Tinei Nyatsvimbo

GeneralRe: ThanksmemberFletch9978-Apr-11 20:36 
Hi Luke,
 
I know this is a very old thread but I just wanted to let you know that your solution is working wonderfully for me and the updated code for parsing the body is perfect.
 
Thankyou so much.
 
Hope all is well.
 

Cheers,
Fletch
Generalcould u plz help me retrirve the bodymemberharsh nathani17-Jun-08 20:07 
i cannot retrieve the body of the message and also if i have an email from gmail received the to cannot be extracted as gmail uses to: with lowercase and outlook express uses To: with uppercase. if i convert them all to lower or upper it extracts the (to:fromSmile | :) to:.plz help
GeneralRe: could u plz help me retrirve the bodymemberLuke Niland20-Jun-08 8:19 
hi,
 
What problem are you getting trying to extract the message body, are you getting any errors in the code or is it just not outputting anything?
 
As for the extracting of the too section of the mail, i dont think case matters (i've not got the code handy so i cant check) but i think it converts it to upper case somewhere in the code. The only reason i can think so that not working is the too is in a strange format or place, but I would'nt expect it.
 
Feel free to forward me an example email and ill have a look if you want
 
Cheers
Luke
 

GeneralUnable to write data to transport connection An Established Connection was Aborted by the software in your host machinememberoerslaafroze27-Nov-07 8:49 
i am getting following error messages continously
 
"POP3ERROR-Unexpected Response From Mail server When Connecting"
 
"POP3ERROR-Unexpected Response From Mail server When Sending User"
 
"Unable to write data to transport connection An Established Connection was Aborted by the software in your host machine"
 
"Unexpected error when getting number of emails:Unable to write data to transport connection An Established Connection was Aborted by the software in your host machine"
 
"Unable to write data to transport connection An Established Connection was Aborted by the software in your host machine"
 
can you please tell how to overcome this exception,which software is aborting the established connection.
 
waiting for reply
regards
Oersla Afroze Ahmed

GeneralRe: Unable to write data to transport connection An Established Connection was Aborted by the software in your host machinememberLuke Niland30-Nov-07 3:21 
Hi,
 
Without knowing you exact setup its hard to say exactly what's wrong but it sounds like a connectivity problem.
 
The best way to fault find things like this is to connect to the pop3 server on a command line and issue it some commands to make sure every thing's working.
 
At a command line (or using a client like putty) telnet to you mail server on port 110 i.e.
 
telnet mailserver.domain.com 110
 
When you do that you should get a line back telling you something like the version etc. If you get this far you can then try and login, retrieve message etc using the pop3 command set. Just search Google for them.
 

QuestionHave You Done Anything With Attachments?membermycroft.xxx21-Nov-07 8:04 
Hi Luke,
Great article! Thanks.
 
Have you done any work on attachments?
If so, would you like debugging help?
 
Randy (Mycroft.xxx)
AnswerRe: Have You Done Anything With Attachments?memberLuke Niland21-Nov-07 13:52 
Hi Randy,
 
I have looked tentatively at adding support for attachments, but it's not at all straight forwarded!
 
We would have to build into the app support for MIME types. (http://en.wikipedia.org/wiki/MIME) and that would not be all that easy. I would like to look into it more if people were interested, but it would be a lot of work. I don't mind starting the project off if you would be willing to do some of the work as well.
 
let me know what you think
 
cheers
luke
 

QuestionPlease help me ~~tqmemberedmond100226-Sep-07 4:03 
Hi,
 
Wondering can you answer these two questions for me.Thanks a lot ~~
 
1) About the function "Delete Mail after Downloading",
I didnt tick the concerning function while loading the program
but still can delete mails from the mail server.
Is there any ways to Download mail into the program, and let the mails remains in the mail server?
 
2) When receiving mails in the chinese characters,
the program will show "A problem occured while decoding a base64 email"
Can u teach me what codes I have to write to see chinese characters.
 
Please help me~~ tq
 
Best regards,
Edmond
AnswerRe: Please help me ~~tqmemberLuke Niland26-Sep-07 11:12 
Hi,
 
I'll try and answer your questions in here and not my blog as more people will probably see it!
 
1) In the form code I have purposely left the part that would delete the mail of the server commented out so if you just run the code it wont delete any mail of the server. To delete any mail you will have to tick the box on the form AND uncomment the popConn.MarkForDelete(i) line.
Also note that the mail is only marked for deletion at this point, it is actually deleted when you issue the QUIT command to the server, this is done by the popConn.CloseConn line right at the end.
 
When the program runs and gets mail of your server, it puts the entire content of the message into the strMailContent variable. This includes all the headers, mime types, too/from headers etc. The function called ParseBody then tries to extract only the body text out of the email, and stores it in the strBody variable. If you uncomment out the message box just after where the message gets added to the list you will see all the sections of the email.
 
2)This could prove tricky! The part of my class that attempts to get the body text out isn't brilliant, but at the time i was only dealing with simple messages. I dont really know that much about how you will get the Chinese chars out of the email within vb.net. You will probably have to do something clever regarding what character set you read the email as. You can send me an example email if you like and I can have a look but its not something I have ever dealt with before.

 

GeneralThis is greatmemberSgt Mike3-Sep-07 10:32 
:-DEven if this does sprout some errors at me, finding it saved me hours of work. The hard part was the right query in MSDN and I laughed many times over at this line in your article:
 
Background
When i started to work with the .Net framework, one of the first things I noticed was its lack of support for downloading emails from a mail server. There is very good support for sending mail via the SMTP protocol, but nothing for receiving. The class came about when I needed a way of retrieving log files that were sent as emails, and acting on the information contained in the mail.
 

You can say that again! There sure is no support in VB.Net for downloading emails. I tried walkthroughs, I tried this, I tried that as queries and finally, checked a document when I wanted to do this back in January. I made notes about what I wanted to do then and realized in these notes ... existed the query I should be using! LOL -- got your code as one of the first tries. Then when I read about no support as you wrote it, I wasn't too surprised I had such a difficult time.
 
Thanks. If it needs any tweaking to work, I'll pass along my input.
 
Best,
 
Mike
 
Michael Durthaler
VB.Net Development/Maintenance
Musician, Cincinnati Area (Will play for food Smile | :) )
mdurthaler@sbcglobal.net

GeneralRe: This is greatmemberLuke Niland24-Sep-07 5:51 
Hi Mike,
 
Thanks for the feedback, I know some of the code's not perfect but it got me out of a hole! The support for mail protocols (apart from SMTP) in .NET terrible, i cant believe its all the way up to version 3 of the framework and still not even simple pop3 support.
 
Only good thing about it was I learnt something new!
 
If you make any mods to it ill post them up here and credit you.
 
Cheers
Luke
 

GeneralRe: This is greatmemberSgt Mike25-Sep-07 1:14 
Thanks for the reply. I made the rookie mistake of sending you one via Outlook instead of here. Smile | :)
 
I'll fly by you our final use of the code once we're done. So far, it holds it's own with a few modifications but we don't have it integrated with the rest our application yet -- we're still writing it. I don't see any problems as it works well in and of itself.
 
Best,
 
Mike
 
Michael Durthaler
VB.Net Development/Maintenance
Musician, Cincinnati Area (Will play for food Smile | :) )
mdurthaler@sbcglobal.net

QuestionNeed helpmemberkanzz2-Aug-07 19:50 
Suppose i want to use this POP3 codings in localhost means how can i create the username account and password
AnswerRe: Need helpmemberLuke Niland24-Sep-07 7:59 
I'm not really sure what you mean, if you want to run a pop3 server on your machine you'll have to use Windows2003 server as that has a built in service, or Linux offering
 
Cheers
Luke
 

QuestionIt is not working for me. Pleae helpmemberpgsr25-Jul-07 1:22 
I am new to Dot net technology. Can you please help in implementing this code. when I run this code it give me the following error
 
"Unable to read data from the transport connection. An existing connection was forcibly closed by the remote host"
 
Thnx.
AnswerRe: It is not working for me. Pleae helpmemberLuke Niland27-Jul-07 3:56 
Hi,
 
sounds like you aren't allowed to connect to the pop3 server you are trying to get at. Try connecting on telnet to the server on port 110 (the default pop3 port). If you can on let me know an post what line its giving you the error on and ill have a look.
 
Cheers
Luke
 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130617.1 | Last Updated 13 Mar 2007
Article Copyright 2007 by Luke Niland
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid