
Cliente de Correo con TcpClient, SmtpClient, networkStream y Sockets
Publicado por Marco Antonio (1 intervención) el 04/06/2015 21:51:52
Hola, estoy desarrollando un cliente de correo pero no quiero utilizar ninguna referencia a dlls externas así que desarrolle un envió de correo con SmtpClient y funciona ok, pero cuando quiero leer los correo del buzón no logro hacerlo y al hacer el segundo networkStream.Write me ocurre un error "no se peden leer los datos de la conexion de transporte: se ha anulado una conexion establecida por el software en si equipo host"
El correo que deseo rescatar es de GMail por eso el puerto 995.
El código es el siguiente:
Algún súper entendido que me de una mano?
Saludos
El correo que deseo rescatar es de GMail por eso el puerto 995.
El código es el siguiente:
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
Public Function RecibirCorreo()
Dim hostName As String = "Tu Host de Correo"
Dim userName As String = "Username"
Dim userPassword As String = "Password"
Dim tcpClient As New Net.Sockets.TcpClient
Dim messageNumber As String = "1"
Dim returnMessage As String
Dim sTemp As String
Try
tcpClient.Connect(hostName, 995)
Dim networkStream As Net.Sockets.NetworkStream = tcpClient.GetStream()
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
Dim sendBytes As Byte()
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
sendBytes = Encoding.ASCII.GetBytes("USER" + userName + vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
sTemp = networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
sendBytes = System.Text.Encoding.ASCII.GetBytes("PASS" + userPassword + vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
sTemp = networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
sendBytes = System.Text.Encoding.ASCII.GetBytes("STAT" + vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
sTemp = networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
sendBytes = System.Text.Encoding.ASCII.GetBytes("RETR" + messageNumber + vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
System.Threading.Thread.Sleep(500)
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
returnMessage = Encoding.ASCII.GetString(bytes)
MsgBox(returnMessage.ToString)
sendBytes = Encoding.ASCII.GetBytes("QUIT" + vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
tcpClient.Close()
Return True
Catch ex As Exception
MsgBox(Err.Description & " - No se puede recibir correo o el buzon de entrada esta vacio")
Return False
End Try
End Function
Algún súper entendido que me de una mano?
Saludos
Valora esta pregunta


0