sudipta_
asked on
Parsing e-mail received using POP3 protocol (vb.net)
hi,
I am using the tcpclient object to receive mail using POP3 in VB.net. I save the mail contents in a text file. I want to know if there is a way to retrieve the various headers( To, From, Subject, etc) and decode attatchments if any & retrieve embedded images. Is there any inbuilt support for receiving mail in .net? or is parsing the mail line by line the only way out?
thanks in advance,
sudipta
ps.
this is what a mail i retrieved looks like:
+OK 2259 octets
Received: from webtech15 [203.199.141.93] by webtechdevelopers.com with ESMTP
(SMTPD32-6.06) id AA0E20015E; Mon, 24 Mar 2003 00:39:26 -0500
Message-ID: <000a01c2f1c6$76b49540$5d8 dc7cb@web1 .com>
Reply-To: "Sudipta Bhowmik" <sudipta@webtechdevelopers .com>
From: "Sudipta Bhowmik" <sudipta@webtechdevelopers .com>
To: "sudipta" <sudipta@webtechdevelopers .com>
Subject: test
Date: Mon, 24 Mar 2003 11:00:09 +0530
MIME-Version: 1.0
Content-Type: multipart/related;
type="multipart/alternativ e";
boundary="----=_NextPart_0 00_0006_01 C2F1F4.892 60640"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
X-RCPT-TO: <sudipta@webtechdevelopers .com>
X-UIDL: 342029223
Status: U
This is a multi-part message in MIME format.
------=_NextPart_000_0006_ 01C2F1F4.8 9260640
Content-Type: multipart/alternative;
boundary="----=_NextPart_0 01_0007_01 C2F1F4.892 60640"
------=_NextPart_001_0007_ 01C2F1F4.8 9260640
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
testing
------=_NextPart_001_0007_ 01C2F1F4.8 9260640
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><IMG alt=3D"" hspace=3D0=20
src=3D"cid:000501c2f1c6$6f 67afc0$5d8 dc7cb@web1 .com" align=3Dbaseline=20
border=3D0></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>testing</FONT></D IV></BODY> </HTML>
------=_NextPart_001_0007_ 01C2F1F4.8 9260640--
------=_NextPart_000_0006_ 01C2F1F4.8 9260640
Content-Type: image/gif;
name="bold.gif"
Content-Transfer-Encoding: base64
Content-ID: <000501c2f1c6$6f67afc0$5d8 dc7cb@web1 .com>
R0lGODlhFwAWAJEAAEpNSu/v3g AAAAAAACwA AAAAFwAWAA AIQgADCBxI sKDBgwgTKl zIsKHDhxAT
AphIcSJEigIxOtSosSFHixsrgg wJIONIhh9L kjSpEqXIkx FjypxJs6bN mwECAgA7
------=_NextPart_000_0006_ 01C2F1F4.8 9260640--
I am using the tcpclient object to receive mail using POP3 in VB.net. I save the mail contents in a text file. I want to know if there is a way to retrieve the various headers( To, From, Subject, etc) and decode attatchments if any & retrieve embedded images. Is there any inbuilt support for receiving mail in .net? or is parsing the mail line by line the only way out?
thanks in advance,
sudipta
ps.
this is what a mail i retrieved looks like:
+OK 2259 octets
Received: from webtech15 [203.199.141.93] by webtechdevelopers.com with ESMTP
(SMTPD32-6.06) id AA0E20015E; Mon, 24 Mar 2003 00:39:26 -0500
Message-ID: <000a01c2f1c6$76b49540$5d8
Reply-To: "Sudipta Bhowmik" <sudipta@webtechdevelopers
From: "Sudipta Bhowmik" <sudipta@webtechdevelopers
To: "sudipta" <sudipta@webtechdevelopers
Subject: test
Date: Mon, 24 Mar 2003 11:00:09 +0530
MIME-Version: 1.0
Content-Type: multipart/related;
type="multipart/alternativ
boundary="----=_NextPart_0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
X-RCPT-TO: <sudipta@webtechdevelopers
X-UIDL: 342029223
Status: U
This is a multi-part message in MIME format.
------=_NextPart_000_0006_
Content-Type: multipart/alternative;
boundary="----=_NextPart_0
------=_NextPart_001_0007_
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding:
testing
------=_NextPart_001_0007_
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><IMG alt=3D"" hspace=3D0=20
src=3D"cid:000501c2f1c6$6f
border=3D0></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>testing</FONT></D
------=_NextPart_001_0007_
------=_NextPart_000_0006_
Content-Type: image/gif;
name="bold.gif"
Content-Transfer-Encoding:
Content-ID: <000501c2f1c6$6f67afc0$5d8
R0lGODlhFwAWAJEAAEpNSu/v3g
AphIcSJEigIxOtSosSFHixsrgg
------=_NextPart_000_0006_
There is no builtin support for parsing POP3 mails. Check on w3c.org site. I think they have a project on building of various networking clients and POP3 is one of them. You can use that.
ASKER
yes i figured that out after searching all day:) i did manage to parse out all the headers but now i'm facing another prob in decoding the attachments
basically i found some vb6 code for base64 decoding & converted it to vb.net but it just doesnt work!
i've realised where the prob is but cant solve it. it would be really nice if you could give me a routine for base64 decoding in VB.net or tell me where to find it.
thanks for your time,
sudipta
basically i found some vb6 code for base64 decoding & converted it to vb.net but it just doesnt work!
i've realised where the prob is but cant solve it. it would be really nice if you could give me a routine for base64 decoding in VB.net or tell me where to find it.
thanks for your time,
sudipta
.Net has a class that does base64 encoding/decoding
Convert.FromBase64String
Convert.ToBase64String
Convert.FromBase64String
Convert.ToBase64String
ASKER
i've written this function using the convert class & while it works perfectly for decoding jpeg's & bmp's, it fails if the
encoded string is of a .xml, or .doc or any non-image file. could you pls take a look at my code & tell me where i'm going wrong?
public function decodeattachment(strattnam e as string, str2decode as string)
Dim bytarr As Byte()
Dim i as integer
Dim fstream As System.IO.FileStream
Dim binwriter As System.IO.BinaryWriter
'create a filestream object initialize with filename of the attachment eg. sample.jpg
fstream = New System.IO.FileStream("C:\" + strattname, IO.FileMode.Create)
'create a binarywriter object & initialize with the file stream object
binwriter = New System.IO.BinaryWriter(fst ream)
'put converted base64 string in a byte array
bytIn = Convert.FromBase64String(s tr2Decode)
'write byte by byte to the file
For i = 0 To bytIn.GetUpperBound(0) - 1
binwriter.Write(bytIn(i))
Next
binwriter.Close()
fstream.Close()
End Function
thanks a lot
sudipta
encoded string is of a .xml, or .doc or any non-image file. could you pls take a look at my code & tell me where i'm going wrong?
public function decodeattachment(strattnam
Dim bytarr As Byte()
Dim i as integer
Dim fstream As System.IO.FileStream
Dim binwriter As System.IO.BinaryWriter
'create a filestream object initialize with filename of the attachment eg. sample.jpg
fstream = New System.IO.FileStream("C:\"
'create a binarywriter object & initialize with the file stream object
binwriter = New System.IO.BinaryWriter(fst
'put converted base64 string in a byte array
bytIn = Convert.FromBase64String(s
'write byte by byte to the file
For i = 0 To bytIn.GetUpperBound(0) - 1
binwriter.Write(bytIn(i))
Next
binwriter.Close()
fstream.Close()
End Function
thanks a lot
sudipta
I've been scouring the Internet for weeks for an answer to this same problem, and the best answer I've found so far is here: http://www.quiksoft.com/emdotnet/parse/
Unfortunately it's $499. We haven't bought it yet but are planning to in the next week or so.
Unfortunately it's $499. We haven't bought it yet but are planning to in the next week or so.
ASKER
too bad u have to shell out that much, i'll have to lease my place to buy that component so i have to do it the hard way, anyways, i've found out whats wrong with my decodeattachment function--- the last byte simply wasnt getting written!
the for loop should read-
For i = 0 To bytIn.GetUpperBound(0) binwriter.Write(bytIn(i))
Next
it seems that it desnt matter if the last byte in an image file is present or not, in case text documents, it has to be present thats the reason why image files were getting displayed but others were not.
the for loop should read-
For i = 0 To bytIn.GetUpperBound(0) binwriter.Write(bytIn(i))
Next
it seems that it desnt matter if the last byte in an image file is present or not, in case text documents, it has to be present thats the reason why image files were getting displayed but others were not.
ASKER
i have another doubt, since i'm using the tcpclient object & the POP3 protocol to issue mail commands, i am able to retrieve mails only sequentially
i.e say the stat command returns count of new mails as 3, i issue RETR 1 to fetch the 1st mail but cannot issue RETR 2 unless RETR 1 returns. this makes the process very slow. i can issue the RETR in a thread but since i have only one connection open, i cannot do so.
is there another way of doing this?
i.e say the stat command returns count of new mails as 3, i issue RETR 1 to fetch the 1st mail but cannot issue RETR 2 unless RETR 1 returns. this makes the process very slow. i can issue the RETR in a thread but since i have only one connection open, i cannot do so.
is there another way of doing this?
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ/Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TheLearnedOne
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
PAQ/Refund
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TheLearnedOne
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.