?
Solved

Parsing e-mail received using POP3 protocol (vb.net)

Posted on 2003-03-23
9
Medium Priority
?
824 Views
Last Modified: 2007-12-19
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$5d8dc7cb@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/alternative";

     boundary="----=_NextPart_000_0006_01C2F1F4.89260640"

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.89260640

Content-Type: multipart/alternative;

     boundary="----=_NextPart_001_0007_01C2F1F4.89260640"





------=_NextPart_001_0007_01C2F1F4.89260640

Content-Type: text/plain;

     charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable





testing



------=_NextPart_001_0007_01C2F1F4.89260640

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$6f67afc0$5d8dc7cb@web1.com" align=3Dbaseline=20

border=3D0></FONT></DIV>

<DIV><FONT face=3DArial size=3D2>testing</FONT></DIV></BODY></HTML>



------=_NextPart_001_0007_01C2F1F4.89260640--



------=_NextPart_000_0006_01C2F1F4.89260640

Content-Type: image/gif;

     name="bold.gif"

Content-Transfer-Encoding: base64

Content-ID: <000501c2f1c6$6f67afc0$5d8dc7cb@web1.com>



R0lGODlhFwAWAJEAAEpNSu/v3gAAAAAAACwAAAAAFwAWAAAIQgADCBxIsKDBgwgTKlzIsKHDhxAT

AphIcSJEigIxOtSosSFHixsrggwJIONIhh9LkjSpEqXIkxFjypxJs6bNmwECAgA7



------=_NextPart_000_0006_01C2F1F4.89260640--






0
Comment
Question by:sudipta_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8194357
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.
0
 

Author Comment

by:sudipta_
ID: 8202761
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
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 8203384
.Net has a class that does base64 encoding/decoding

Convert.FromBase64String
Convert.ToBase64String
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:sudipta_
ID: 8208519
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(strattname 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(fstream)
       
       'put converted base64 string in a byte array
        bytIn = Convert.FromBase64String(str2Decode)

       '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
0
 
LVL 4

Expert Comment

by:timmyt851
ID: 8216112
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.
0
 

Author Comment

by:sudipta_
ID: 8217865
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.
0
 

Author Comment

by:sudipta_
ID: 8217913
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?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 9688258
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
0
 
LVL 2

Accepted Solution

by:
Lunchy earned 0 total points
ID: 9735367
PAQed, with refund (100)

Lunchy
Friendly Neighbourhood Community Support Admin
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question