Als ik een TCPClient open in functie a dan knalt mijn programma eruit bij functie b als ik er commando's naar wil zenden...
De connectie opzetten gaat prima, maar in de functie readmail knalt ie eruit bij de laatste regel die niet gecomment is (response = Send.....)
De connectie opzetten gaat prima, maar in de functie readmail knalt ie eruit bij de laatste regel die niet gecomment is (response = Send.....)
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
| Public Class pop3
Dim tcpC As New TcpClient()
Function SendCommand(ByRef netstream As NetworkStream, ByVal sToSend 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)
Dim bytes(tcpC.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
Function Connect(ByVal host As String, ByVal user As String, ByVal pass As String) As String
Dim response As String
Dim netstream As NetworkStream
Try
tcpC.Connect(host, 110)
Catch ex As Exception
response = ex.Message
Return response
Exit Function
End Try
netstream = tcpC.GetStream()
response = GetResponse(netstream)
response = SendCommand(netstream, "user " & user & vbCrLf)
response = SendCommand(netstream, "pass " & pass & vbCrLf)
Return response
End Function
Function Disconnect() As String
Dim response As String
Dim netstream As NetworkStream
Dim thisResponse As String
thisResponse = SendCommand(netstream, "QUIT" & vbCrLf)
tcpC.Close()
End Function
Function ReadMail() As String
Dim netstream As NetworkStream
Dim response As String
netstream = tcpC.GetStream()
response = SendCommand(netstream, "stat" & vbCrLf)
'Dim tmpArray() As String
'tmpArray = Split(response, " ")
'Dim thisMess As Integer
'Dim numMess As String = tmpArray(1)
'response = ""
'If CInt(numMess) > 0 Then
'numMess has the total nummber of message waiting for us on the server
'For thisMess = 1 To CInt(numMess)
'response += (SendCommand(netstream, "retr " & thisMess & vbCrLf))
'Next
'Else
'response = "No messages"
'End If
Return response
End Function
End Class |