473,507 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET/VB Receiving Mail

I have this code to get the messages from a mail server, but whenever I try
to connect it gives me the error "Cast from string " " to type 'Double' is
not valid." Why is it doing this?

Here is a sample of the vars I pass to the connect procedure:
myClient.Connect("mail.server.com", "user_name", "password")

<script runat="server">
Public Class Pop3
Inherits System.Net.Sockets.TcpClient

Public Shared totalBytes As Double = 0

Public Sub New()
End Sub

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

MyBase.Connect(server, 110)
sRes = GetWebResponse()
If Not (sRes.Substring(0, 3) = "+OK") Then
Throw New Pop3Exception("H1: " & sRes)
End If

message = "USER " & username & Microsoft.VisualBasic.Chr(13) &
Microsoft.VisualBasic.Chr(10)
Write(message)
sRes = GetWebResponse()
If Not (sRes.Substring(0, 3) = "+OK") Then
Throw New Pop3Exception("H2: " & sRes)
End If

message = "PASS " & password & Microsoft.VisualBasic.Chr(13) &
Microsoft.VisualBasic.Chr(10)
Write(message)
sRes = GetWebResponse()
If Not (sRes.Substring(0, 3) = "+OK") Then
Throw New Pop3Exception("H3: " & sRes)
End If
End Sub

Public Sub Disconnect()
Dim message As String
Dim sRes As String

message = "QUIT" & Microsoft.VisualBasic.Chr(13) & "" &
Microsoft.VisualBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse()
If Not (sRes.Substring(0, 3) = "+OK") Then
Throw New Pop3Exception(sRes)
End If
End Sub

Public Function List() As ArrayList
Dim message As String
Dim sRes As String
Dim retval As ArrayList = New ArrayList()

message = "LIST" & Microsoft.VisualBasic.Chr(13) & "" &
Microsoft.VisualBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse()
If Not (sRes.Substring(0, 3) = "+OK") Then
Throw New Pop3Exception(sRes)
End If

While True
sRes = GetWebResponse()
If sRes = "." & Microsoft.VisualBasic.Chr(13) & "" &
Microsoft.VisualBasic.Chr(10) & "" Then
Return retval
Else
Dim msg As Pop3Message = New Pop3Message()
Dim seps As Char() = {" "c}
Dim values As String() = sRes.Split(seps)
msg.number = Int32.Parse(values(0))
msg.bytes = Int32.Parse(values(1))
totalBytes += msg.bytes
msg.retrieved = False
retval.Add(msg)
' continue
End If
End While
End Function

Public Function Retrieve(ByVal rhs As Pop3Message) As Pop3Message
Dim message As String
Dim sRes As String

Dim msg As Pop3Message = New Pop3Message()
msg.bytes = rhs.bytes
msg.number = rhs.number

message = "RETR " + rhs.number + "" & Microsoft.VisualBasic.Chr(13)
& "" & Microsoft.VisualBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse()
If Not (sRes.Substring(0, 3) = "+OK") Then
Throw New Pop3Exception(sRes)
End If
msg.retrieved = True

While True
sRes = GetWebResponse()
If sRes = "." & Microsoft.VisualBasic.Chr(13) & "" &
Microsoft.VisualBasic.Chr(10) & "" Then
Exit While
Else
msg.message += sRes
End If
End While
Return msg
End Function

Public Sub Delete(ByVal rhs As Pop3Message)
Dim message As String
Dim sRes As String

message = "DELE " + rhs.number + "" & Microsoft.VisualBasic.Chr(13)
& "" & Microsoft.VisualBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse()
If Not (sRes.Substring(0, 3) = "+OK") Then
Throw New Pop3Exception(sRes)
End If
End Sub

Private Sub Write(ByVal message As String)
Dim en As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding()
Dim WriteBuffer(1024) As Byte
WriteBuffer = en.GetBytes(message)
Dim stream As NetworkStream = GetStream()
stream.Write(WriteBuffer, 0, WriteBuffer.Length)
End Sub

Private Function GetWebResponse() As String
Dim enc As System.Text.ASCIIEncoding = New System.Text.ASCIIEncoding()
Dim serverbuff(1024) As Byte
Dim stream As NetworkStream = GetStream()
Dim count As Integer = 0

While True
Dim buff(2) As Byte
Dim bytes As Integer = stream.Read(buff, 0, 1)

If bytes = 1 Then
serverbuff(count) = buff(0)
count += 1
If buff(0) = ControlChars.NewLine Then
' break
Exit While
End If
Else
' break
Exit While
End If
End While

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

Public ReadOnly Property getTotalBytes() As Double
Get
Return totalBytes
End Get
End Property
End Class

Public Class Pop3Exception
Inherits System.ApplicationException

Public Sub New(ByVal str As String)
MyBase.New(str)
End Sub
End Class

Public Class Pop3Message
Public number As Long
Public bytes As Long
Public retrieved As Boolean
Public message As String
End Class
</script>

--
Alex C. Barberi
Chief Executive Officer
VisionForce
http://www.visionforceweb.com

Mar 3 '06 #1
1 1705
Thanks but I'd prefer to write my own.

This line is giving me the error (in GetWebResponse):
"If buff(0) = ControlChars.NewLine Then"

I converted this project from C# and this was the code they used:
if (buff[0] == '\n') {

--
Alex C. Barberi
Chief Executive Officer
VisionForce
http://www.visionforceweb.com

"Spam Catcher" wrote:
=?Utf-8?B?QWxleCBDLiBCYXJiZXJp?=
<Al**********@discussions.microsoft.com> wrote in
news:12**********************************@microsof t.com:
I have this code to get the messages from a mail server, but whenever
I try to connect it gives me the error "Cast from string " " to type
'Double' is not valid." Why is it doing this?


Which line is giving you that error?

Take a look at nsoftware's IP*Works suite - it's only 99.00 per server or
499 for a royalty free license... IP*works has severa components to
retrieve e-mail from IMAP to POP. It also contains many other components
too (it's a pretty good deal for the price).

Otherwise there are a bunch of other (more robust) mail components out
there too...

--
Stan Kee (sp**********@rogers.com)

Boycott StarForce!
http://www.glop.org/starforce

Mar 3 '06 #2

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

Similar topics

0
1248
by: BigSizeXXL | last post by:
hi, i'm new to python and have a couple of questions about working with smtp. i read that you need a pop3 service for receiving mails. i want to create my own (private) mail service. i'm using a...
1
1662
by: Sajsal | last post by:
Hi all I am developing a web app in which the client wants an email sending and receiving functionality. Is it possible in C#. If yes where should I start. If anyone could tell that how long...
1
1213
by: Jigar Mehta | last post by:
Hye friends!!! Jigar Mehta from India. Currently making one program in VC++ like outlook express that sends and receives mails from the server (pop3, and smtp server only)... I can not find...
2
1659
by: mamatha | last post by:
Hi, I want to send Email in VB to mutiple users through SMTP and receiving emails thruegh IMAP.How can i built.If any one knows the source code or URL please let me know Mamatha
5
19573
by: sophocles the wise | last post by:
I am researching this topic without a satisfactory solution so far. Please let me know which is the easiest way to receive email using VB code. All I need is to test source address or subject line...
5
1384
by: smahaboob | last post by:
Hi good morning to all, iam creating email application in asp.net, When iam executing my application it is executing but iam not able receive mails. My mails are...
1
2834
by: markus1313 | last post by:
Dead simple question. I've setup a Windows XP box to run RT (Request Tracker). Part of the tool's functionality is to send and receive e-mails. Can I use the SMTP functionality that comes with IIS to...
13
1523
by: davjoh | last post by:
The following describes the problem I am having. Can anyone help? $send_to = "davjoh123@yahoo.com"; $send_to = "production@advisiongraphics.com"; $send_to =...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
412
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.