473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

pop3 to db

Is there a mechanism to montior a POP3 mailbox, then add the messagesa to a
database? If not, I'm assuming that I'd need to build a service that would
poll the POP3 account periodically, then process accordingly.

Thanks,

Craig
Nov 21 '05 #1
3 1289
Hi,

I converted this c# pop3 mail class to vb.net. Maybe this will
help.

http://www.programmersheaven.com/2/Art_CSharp_3

How to use

Dim mail As New Pop3Mail

mail.Connect("mail.xxxx.net", "user", "password")

For Each msg As Pop3Mail.Pop3Message In mail.List

Trace.WriteLine(DirectCast(mail.Retrieve(msg),
Pop3Mail.Pop3Message).message)

Next

The class

Imports System.Net.Sockets

Public Class Pop3Mail

Inherits System.Net.Sockets.TcpClient

Public Class Pop3Exception

Inherits System.ApplicationException
Public Sub New(ByVal str As String)

MyBase.New(str)
End Sub 'New

End Class 'Pop3Exception

Public Class Pop3Message

Public number As Long

Public bytes As Long

Public retrieved As Boolean

Public message As String

End Class 'Pop3Message

Public Overloads Sub Connect(ByVal server As String, ByVal username As
String, ByVal password As String)

Dim message As String

Dim strResponse As String

Connect(server, 110)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(Response)

End If

message = "USER " + username + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

message = "PASS " + password + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Connect

Public Sub Disconnect()

Dim message As String

Dim strResponse As String

message = "QUIT" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Disconnect

Public Function List() As ArrayList

Dim message As String

Dim strResponse As String

Dim retval As New ArrayList

message = "LIST" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Return retval

Else

Dim msg As New Pop3Message

Dim seps As Char() = " ".ToCharArray

Dim values As String() = strResponse.Split(seps)

msg.number = Int32.Parse(values(0))

msg.bytes = Int32.Parse(values(1))

msg.retrieved = False

retval.Add(msg)

End If

End While

End Function 'List

Public Function Retrieve(ByVal rhs As Pop3Message) As Pop3Message

Dim message As String

Dim strResponse As String

Dim msg As New Pop3Message

msg.bytes = rhs.bytes

msg.number = rhs.number

message = "RETR " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

msg.retrieved = True

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Exit While

Else

msg.message += strResponse

End If

End While

Return msg

End Function 'Retrieve

Private Sub Write(ByVal message As String)

Dim en As New System.Text.ASCIIEncoding

Dim WriteBuffer(1023) As Byte

WriteBuffer = en.GetBytes(message)

Dim stream As NetworkStream = GetStream()

stream.Write(WriteBuffer, 0, WriteBuffer.Length)

Debug.WriteLine("WRITE:" + message)

End Sub 'Write

Public Sub Delete(ByVal rhs As Pop3Message)

Dim message As String

Dim strResponse As String

message = "DELE " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Delete

Private Function Response() As String

Dim enc As New System.Text.ASCIIEncoding

Dim serverbuff() As Byte = New [Byte](1023) {}

Dim stream As NetworkStream = GetStream()

Dim count As Integer = 0

While True

Dim buff() As Byte = New [Byte](1) {}

Dim bytes As Integer = stream.Read(buff, 0, 1)

If bytes = 1 Then

serverbuff(count) = buff(0)

count += 1

If buff(0) = Asc(vbLf) Then

Exit While

End If

Else

Exit While

End If

End While

Dim retval As String = enc.GetString(serverbuff, 0, count)

Debug.WriteLine("READ:" + retval)

Return retval

End Function 'Response

End Class

Ken

---------------------------------
"Craig Buchanan" <re***@newsgroup.com> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
Is there a mechanism to montior a POP3 mailbox, then add the messagesa to a
database? If not, I'm assuming that I'd need to build a service that would
poll the POP3 account periodically, then process accordingly.

Thanks,

Craig

Nov 21 '05 #2
Hi,

I converted this c# pop3 mail class to vb.net. Maybe this will
help.

http://www.programmersheaven.com/2/Art_CSharp_3

How to use

Dim mail As New Pop3Mail

mail.Connect("mail.xxxx.net", "user", "password")

For Each msg As Pop3Mail.Pop3Message In mail.List

Trace.WriteLine(DirectCast(mail.Retrieve(msg),
Pop3Mail.Pop3Message).message)

Next

The class

Imports System.Net.Sockets

Public Class Pop3Mail

Inherits System.Net.Sockets.TcpClient

Public Class Pop3Exception

Inherits System.ApplicationException
Public Sub New(ByVal str As String)

MyBase.New(str)
End Sub 'New

End Class 'Pop3Exception

Public Class Pop3Message

Public number As Long

Public bytes As Long

Public retrieved As Boolean

Public message As String

End Class 'Pop3Message

Public Overloads Sub Connect(ByVal server As String, ByVal username As
String, ByVal password As String)

Dim message As String

Dim strResponse As String

Connect(server, 110)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(Response)

End If

message = "USER " + username + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

message = "PASS " + password + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Connect

Public Sub Disconnect()

Dim message As String

Dim strResponse As String

message = "QUIT" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Disconnect

Public Function List() As ArrayList

Dim message As String

Dim strResponse As String

Dim retval As New ArrayList

message = "LIST" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Return retval

Else

Dim msg As New Pop3Message

Dim seps As Char() = " ".ToCharArray

Dim values As String() = strResponse.Split(seps)

msg.number = Int32.Parse(values(0))

msg.bytes = Int32.Parse(values(1))

msg.retrieved = False

retval.Add(msg)

End If

End While

End Function 'List

Public Function Retrieve(ByVal rhs As Pop3Message) As Pop3Message

Dim message As String

Dim strResponse As String

Dim msg As New Pop3Message

msg.bytes = rhs.bytes

msg.number = rhs.number

message = "RETR " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

msg.retrieved = True

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Exit While

Else

msg.message += strResponse

End If

End While

Return msg

End Function 'Retrieve

Private Sub Write(ByVal message As String)

Dim en As New System.Text.ASCIIEncoding

Dim WriteBuffer(1023) As Byte

WriteBuffer = en.GetBytes(message)

Dim stream As NetworkStream = GetStream()

stream.Write(WriteBuffer, 0, WriteBuffer.Length)

Debug.WriteLine("WRITE:" + message)

End Sub 'Write

Public Sub Delete(ByVal rhs As Pop3Message)

Dim message As String

Dim strResponse As String

message = "DELE " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Delete

Private Function Response() As String

Dim enc As New System.Text.ASCIIEncoding

Dim serverbuff() As Byte = New [Byte](1023) {}

Dim stream As NetworkStream = GetStream()

Dim count As Integer = 0

While True

Dim buff() As Byte = New [Byte](1) {}

Dim bytes As Integer = stream.Read(buff, 0, 1)

If bytes = 1 Then

serverbuff(count) = buff(0)

count += 1

If buff(0) = Asc(vbLf) Then

Exit While

End If

Else

Exit While

End If

End While

Dim retval As String = enc.GetString(serverbuff, 0, count)

Debug.WriteLine("READ:" + retval)

Return retval

End Function 'Response

End Class

Ken

---------------------------------
"Craig Buchanan" <re***@newsgroup.com> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
Is there a mechanism to montior a POP3 mailbox, then add the messagesa to a
database? If not, I'm assuming that I'd need to build a service that would
poll the POP3 account periodically, then process accordingly.

Thanks,

Craig

Nov 21 '05 #3
thanks a lot!

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:eg****************@TK2MSFTNGP14.phx.gbl...
Hi,

I converted this c# pop3 mail class to vb.net. Maybe this will
help.

http://www.programmersheaven.com/2/Art_CSharp_3

How to use

Dim mail As New Pop3Mail

mail.Connect("mail.xxxx.net", "user", "password")

For Each msg As Pop3Mail.Pop3Message In mail.List

Trace.WriteLine(DirectCast(mail.Retrieve(msg),
Pop3Mail.Pop3Message).message)

Next

The class

Imports System.Net.Sockets

Public Class Pop3Mail

Inherits System.Net.Sockets.TcpClient

Public Class Pop3Exception

Inherits System.ApplicationException
Public Sub New(ByVal str As String)

MyBase.New(str)
End Sub 'New

End Class 'Pop3Exception

Public Class Pop3Message

Public number As Long

Public bytes As Long

Public retrieved As Boolean

Public message As String

End Class 'Pop3Message

Public Overloads Sub Connect(ByVal server As String, ByVal username As
String, ByVal password As String)

Dim message As String

Dim strResponse As String

Connect(server, 110)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(Response)

End If

message = "USER " + username + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

message = "PASS " + password + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Connect

Public Sub Disconnect()

Dim message As String

Dim strResponse As String

message = "QUIT" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Disconnect

Public Function List() As ArrayList

Dim message As String

Dim strResponse As String

Dim retval As New ArrayList

message = "LIST" + vbCr + vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Return retval

Else

Dim msg As New Pop3Message

Dim seps As Char() = " ".ToCharArray

Dim values As String() = strResponse.Split(seps)

msg.number = Int32.Parse(values(0))

msg.bytes = Int32.Parse(values(1))

msg.retrieved = False

retval.Add(msg)

End If

End While

End Function 'List

Public Function Retrieve(ByVal rhs As Pop3Message) As Pop3Message

Dim message As String

Dim strResponse As String

Dim msg As New Pop3Message

msg.bytes = rhs.bytes

msg.number = rhs.number

message = "RETR " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

msg.retrieved = True

While True

strResponse = Response()

If strResponse = "." & vbCr & vbLf Then

Exit While

Else

msg.message += strResponse

End If

End While

Return msg

End Function 'Retrieve

Private Sub Write(ByVal message As String)

Dim en As New System.Text.ASCIIEncoding

Dim WriteBuffer(1023) As Byte

WriteBuffer = en.GetBytes(message)

Dim stream As NetworkStream = GetStream()

stream.Write(WriteBuffer, 0, WriteBuffer.Length)

Debug.WriteLine("WRITE:" + message)

End Sub 'Write

Public Sub Delete(ByVal rhs As Pop3Message)

Dim message As String

Dim strResponse As String

message = "DELE " & rhs.number & vbCr & vbLf

Write(message)

strResponse = Response()

If strResponse.Substring(0, 3) <> "+OK" Then

Throw New Pop3Exception(strResponse)

End If

End Sub 'Delete

Private Function Response() As String

Dim enc As New System.Text.ASCIIEncoding

Dim serverbuff() As Byte = New [Byte](1023) {}

Dim stream As NetworkStream = GetStream()

Dim count As Integer = 0

While True

Dim buff() As Byte = New [Byte](1) {}

Dim bytes As Integer = stream.Read(buff, 0, 1)

If bytes = 1 Then

serverbuff(count) = buff(0)

count += 1

If buff(0) = Asc(vbLf) Then

Exit While

End If

Else

Exit While

End If

End While

Dim retval As String = enc.GetString(serverbuff, 0, count)

Debug.WriteLine("READ:" + retval)

Return retval

End Function 'Response

End Class

Ken

---------------------------------
"Craig Buchanan" <re***@newsgroup.com> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl...
Is there a mechanism to montior a POP3 mailbox, then add the messagesa to
a
database? If not, I'm assuming that I'd need to build a service that
would
poll the POP3 account periodically, then process accordingly.

Thanks,

Craig

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lev Altshuler | last post by:
Hi, I am trying to count email messages in the mailbox and read their headers. In case that there are some messages on the POP3 server and they haven't yet got to the Inbox, I get a number of...
0
by: Eric McDaniel | last post by:
This may be a question for ActiveState support, but just in case anyone out there knows what the problem is... My call to Net::POP3->new() works fine when run through the perl interpreter, but...
4
by: Ron Vecchi | last post by:
I a runnning w2k3 pop3 mail server that came with iis6. I would like to write an application that progammtically creates the new mailboxes in an already established mail domain. Does anyone know...
2
by: Rui | last post by:
I need to write a proxy between pop3 client and pop3+ssl server. This proxy will receive pop3 commands from the client and will translate those commands for a pop3+ssl server, then it will receive...
2
by: Mike Brearley | last post by:
I need to write a script that will check a catch-all mailbox (pop3) and send a non delivery report back to the sender of the email. Background info: I have a domain hosted on a site that offers...
2
by: Shimon Sim | last post by:
Is there a way to get e-mails with attachments using .NET 2.0? If not does anybody knows a component that can do this? Thank you, Shimon.
1
by: bobano | last post by:
Hi everyone, I am writing a POP3 Client program in Perl. You connect to a POP3 Server and have a running conversation with the mail server using commands from the RFC 1939 Post Office Protocol....
4
by: =?Utf-8?B?QWxwYW5h?= | last post by:
I am making a thin email client and want to get emails from a pop3 server...Is there any built in support in C# to get emails from a pop3 server and parse the email to show up on the UI ?
0
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
Like many people, I normally use Yahoo! Mail via the web and like to keep all my emails stored on the Yahoo! server. However sometimes I can’t get access to a PC/the web and I download my emails...
5
by: Craig Buchanan | last post by:
I would like to monitor a POP3 mailbox with multiple clients. However, I want to ensure that each message is processed by only one client. In essence, I would like to treat a POP3 mailbox like a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.