Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Services > Read POP 3 Mail.

Reply
Thread Tools

Read POP 3 Mail.

 
 
Programmer
Guest
Posts: n/a
 
      05-24-2004
Hi all
I wan't to know if i'm able to read mail from a mail server. My mail server
is a pop3 server (UNIX) and i want to be able to get the mails from an aspx
or an asmx. with out using external objs.
Only classes from the .NET

Is there a way??
Thanks in advance


 
Reply With Quote
 
 
 
 
Calvin Luttrell/ProjectThunder.com
Guest
Posts: n/a
 
      05-24-2004
If you search the internet you can find C# classes that can do this.

I wrote some stuff in VB.Net I've haven't tested it in about 8 months but it might get you started or at least convince you to purchase a component.

-Calvin Luttrell
ProjectThunder.com


Public Class Pop3

Inherits BusniessThunder

Implements ThunderInterface

Private oTCP As New TcpClient()

Private oStream As NetworkStream

Private _name As String

Private _ds As DataSet

Private _pagedata As Hashtable

#Region "Thunder Interface Stuff"

Property PageData() As Hashtable Implements ThunderInterface.PageData

Get

Return _pagedata

End Get



Set(ByVal Value As Hashtable)

_pagedata = Value

End Set

End Property

Property Name() As String Implements ThunderInterface.Name

Get

Return _name

End Get



Set(ByVal Value As String)

_name = Value

End Set





End Property

Property DS() As DataSet Implements ThunderInterface.DS

Get

Return _ds

End Get



Set(ByVal Value As DataSet)

_ds = Value

End Set

End Property

Function Execute() As DataSet Implements ThunderInterface.Execute

If _name.ToUpper = "DELETEMESSAGES" Then

Else

_ds = GetMessages()

End If

Return _ds

End Function

Function Logout()





SendCommand(oStream, "QUIT" + vbCrLf)

oTCP.Close()

End Function





Function DeleteMessages()

Dim orow As DataRow

For Each orow In _ds.Tables(0).Rows

If orow.RowState = DataRowState.Deleted Then

DeleteMessage(orow)

End If

Next

End Function



Sub DeleteMessage(ByVal orow As DataRow)

SendCommand(oStream, "DELE " + orow("Message-ID").ToString + vbCrLf)

End Sub



Function ExecuteThunder(ByVal oThunder As ThunderInterface)

' oThunder.PageData() = GetPageData()

oThunder.Execute()

End Function



#End Region

Sub Login()

Dim sRes As String

oTCP.Connect(_pagedata("HOST"), 110)

oStream = oTCP.GetStream

System.Diagnostics.Debug.WriteLine(GetResponse(oSt ream))

sRes = SendCommand(oStream, "user " + _pagedata("USER") + vbCrLf)

If sRes.StartsWith("-ERR") Then Exit Sub

System.Diagnostics.Debug.WriteLine(sRes)

sRes = SendCommand(oStream, "pass " + _pagedata("PASS") + vbCrLf)

If sRes.StartsWith("-ERR") Then Exit Sub

System.Diagnostics.Debug.WriteLine(sRes)





End Sub

Private Function GetMessages() As DataSet

Dim sRes As String

Dim sMess As String

Dim iNum As Integer

Dim oDS As New DataSet()

Login()

sRes = SendCommand(oStream, "stat" + vbCrLf)

If sRes.StartsWith("-ERR") Then Exit Function

System.Diagnostics.Debug.WriteLine(sRes)

Dim tmpArray() As String

tmpArray = Split(sRes, " ")

Dim thisMess As Integer

Dim numMess As String = tmpArray(1)





For thisMess = CInt(numMess) - 1 To 1 Step -1

' System.Threading.Thread.Sleep(30)

sMess = SendCommand(oStream, "top " + thisMess.ToString + " 10" + vbCrLf)

If sMess.StartsWith("+OK") And sMess.IndexOf(": ") > 0 Then

ParseMessage(sMess, oDS)

End If

Next

Return oDS

End Function

Function ParseMessage(ByVal sData As String, ByRef oEmailData As DataSet)

Dim iStart As Integer

Dim iEnd As Integer

Dim inextpair As Integer

Dim sMessage As String = ""

Dim sBody As String

Dim iLen As Integer

Dim iPart As Integer

Dim sname As String

Dim svalue As String

If oEmailData Is Nothing Then oEmailData = New DataSet()





If Not oEmailData.Tables.Contains("Data") Then oEmailData.Tables.Add("Data")

Dim orow As DataRow = oEmailData.Tables("Data").NewRow

Try

'Get Header and Body

sMessage = sData.Substring(1, sData.IndexOf(vbCrLf + vbCrLf))

sBody = sData.Substring(sData.IndexOf(vbCrLf + vbCrLf))



Catch

Exit Function

Finally

sData = Nothing

End Try



'Creppy Crawler

'Get Starting postion of first name pair

iPart = sMessage.IndexOf(": ", 1) + 2



'go back to name :

iStart = sMessage.LastIndexOf(vbCrLf, iPart) + 2

'get entire length of email

iLen = sMessage.Length

Try

'work until end of email

Do While iStart < iLen

'make the line we are working on is part of the name value pair

If iPart + 2 > iLen Then Exit Do

If Not sMessage.IndexOf(": ", iPart + 2) = -1 Then

'Find the next ": " for that next name pair

iPart = sMessage.IndexOf(": ", iPart) + 2

'This should shuld check for a vbcrlf between crawling to the next name pair

'This is for when someone puts ": " the freak'n suject

If sMessage.Substring(iStart, iPart - iStart).IndexOf(vbCrLf) < 0 Then

iPart = sMessage.IndexOf(": ", iPart) + 2

End If

'crawl back to find the end of the last line

inextpair = sMessage.LastIndexOf(vbCrLf, iPart) + 2

'This gives us the postion in the mini-string which is actually the length of the amount of data we want

iEnd = sMessage.Substring(iStart, inextpair - iStart).LastIndexOf(vbCrLf) + 2

Else

iEnd = iLen - iStart

End If

'Mini me string for parsing name value pair

Dim stemp = sMessage.Substring(iStart, iEnd)

sname = stemp.Substring(0, stemp.IndexOf(": "))

svalue = stemp.Substring(stemp.IndexOf(": ") + 2)

'check to see if the colomn exists yet

If Not oEmailData.Tables("Data").Columns.Contains(sname) Then

'add colomn

oEmailData.Tables("Data").Columns.Add(sname)

End If



'assign value

orow(sname) = svalue

iStart += iEnd

Loop

Catch ex As Exception

System.Diagnostics.Debug.WriteLine(ex.Message)



End Try







'grab body and stick it in the table

If Not oEmailData.Tables("Data").Columns.Contains("BODY") Then

oEmailData.Tables("Data").Columns.Add("BODY")

End If

orow("BODY") = sBody

'add row

oEmailData.Tables(0).Rows.Add(orow)

'TODO parse body remove attachments



Return oEmailData

End Function

Function SendCommand(ByRef netstream As NetworkStream, ByVal sToSend As String) As String

Dim bData() As Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)

netstream.Write(bData, 0, bData.Length())

Return GetResponse(netstream)

End Function

' check if there is a response to get and return it

Function GetResponse(ByRef netstream As NetworkStream) As String

Dim bytes(oTCP.ReceiveBufferSize) As Byte

Dim ret As Integer = netstream.Read(bytes, 0, bytes.Length)

' Returns the data received

Dim returndata As String = Encoding.ASCII.GetString(bytes)

Return returndata

End Function



End Class


> Hi all
> I wan't to know if i'm able to read mail from a mail server. My mail server
> is a pop3 server (UNIX) and i want to be able to get the mails from an aspx
> or an asmx. with out using external objs.
> Only classes from the .NET
>
> Is there a way??
> Thanks in advance


 
Reply With Quote
 
 
 
 
Chad Z. Hower aka Kudzu
Guest
Posts: n/a
 
      05-24-2004
"Programmer" <(E-Mail Removed)> wrote in news:#ZkLpzVQEHA.2520
@TK2MSFTNGP11.phx.gbl:
> I wan't to know if i'm able to read mail from a mail server. My mail server
> is a pop3 server (UNIX) and i want to be able to get the mails from an aspx
> or an asmx. with out using external objs.
> Only classes from the .NET


Yes - but you'll have installation issues with CDO and other.

This assembly is .NET, and free but you have to distribute it.
http://www.indyproject.org/


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
No pop-up but how about a pop quiz? (OT) Bone Ur HTML 4 12-19-2007 01:32 AM
How to do server-side processing and then display pop-up with pop-up blocker enabled domtam@hotmail.com ASP .Net 2 02-04-2006 06:03 PM
pop up prevention problem; for wanted pop ups joe doe Firefox 2 03-03-2005 08:08 AM
Pop-up to Buy Pop-up software William Young Computer Support 4 01-24-2004 12:28 AM
Pop-Up Menager (pop-up blocker), to update it library? Ulisse Computer Information 1 10-27-2003 08:31 PM



Advertisments