473,659 Members | 2,582 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.Connec t("mail.server. com", "user_name" , "password")

<script runat="server">
Public Class Pop3
Inherits System.Net.Sock ets.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.Visua lBasic.Chr(13) &
Microsoft.Visua lBasic.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.Visua lBasic.Chr(13) &
Microsoft.Visua lBasic.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.Visua lBasic.Chr(13) & "" &
Microsoft.Visua lBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse( )
If Not (sRes.Substring (0, 3) = "+OK") Then
Throw New Pop3Exception(s Res)
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.Visua lBasic.Chr(13) & "" &
Microsoft.Visua lBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse( )
If Not (sRes.Substring (0, 3) = "+OK") Then
Throw New Pop3Exception(s Res)
End If

While True
sRes = GetWebResponse( )
If sRes = "." & Microsoft.Visua lBasic.Chr(13) & "" &
Microsoft.Visua lBasic.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(val ues(0))
msg.bytes = Int32.Parse(val ues(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.Visua lBasic.Chr(13)
& "" & Microsoft.Visua lBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse( )
If Not (sRes.Substring (0, 3) = "+OK") Then
Throw New Pop3Exception(s Res)
End If
msg.retrieved = True

While True
sRes = GetWebResponse( )
If sRes = "." & Microsoft.Visua lBasic.Chr(13) & "" &
Microsoft.Visua lBasic.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.Visua lBasic.Chr(13)
& "" & Microsoft.Visua lBasic.Chr(10) & ""
Write(message)
sRes = GetWebResponse( )
If Not (sRes.Substring (0, 3) = "+OK") Then
Throw New Pop3Exception(s Res)
End If
End Sub

Private Sub Write(ByVal message As String)
Dim en As System.Text.ASC IIEncoding = New System.Text.ASC IIEncoding()
Dim WriteBuffer(102 4) As Byte
WriteBuffer = en.GetBytes(mes sage)
Dim stream As NetworkStream = GetStream()
stream.Write(Wr iteBuffer, 0, WriteBuffer.Len gth)
End Sub

Private Function GetWebResponse( ) As String
Dim enc As System.Text.ASC IIEncoding = New System.Text.ASC IIEncoding()
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(buf f, 0, 1)

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

Dim retval As String = enc.GetString(s erverbuff, 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.Applicat ionException

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 1713
Thanks but I'd prefer to write my own.

This line is giving me the error (in GetWebResponse) :
"If buff(0) = ControlChars.Ne wLine 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?QWxleCBDLiB CYXJiZXJp?=
<Al**********@d iscussions.micr osoft.com> wrote in
news:12******** *************** ***********@mic rosoft.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**********@r ogers.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
1256
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 mail server based upon smtps.py, but i'm still looking for a pop3 service to receive mails that also works with smtps.py together. i would be very happy if someone could send me such code. another question: if i have this (smtp server and pop3 mail...
1
1675
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 would it take to develop and the human resources etc I'll be very thankful Regards
1
1217
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 commands that are needed for communication with server for receiving a mail with attachment.. Currently I am able to get the mail without attachment (through socket programming only).. So, please help me if you know any reference from where I can get...
2
1676
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
19580
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 for the right email, and then click a link inside that email. I've seen some people suggested MAPI component, but it's missing in my complete components list (not only in the toolbar). But I see an Outlook Express component, which I suspect is...
5
1391
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 temperorly storing in Queue. if bad mails are there then these also stored in BAD folder. But after iam not able to receiving mail thanks
1
2841
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 both send and, more importantly, *receive* e-mail? Or, do I need to install a POP3 server on the box to all it to receive e-mail? Basically, all I'm try to do is send e-mail to my new machine and have those e-mails appear in...
13
1537
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 = "advision_galiano@mac.com";
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2759
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 we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.