I am trying to create an email reader in vb.net 2008 but when I use the following code I get an error message saying
"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."
"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."
Code:
Imports System.Net.Sockets
Imports System.Text
Public Class Home
Private Sub GetMailButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetMailButton.Click
Dim tcpClient As New TcpClient()
tcpClient.Connect("pop.gmail.com", Convert.ToInt32("995"))
Dim netStream As NetworkStream = tcpClient.GetStream()
Dim strReader As New System.IO.StreamReader(netStream)
RichTextBox1.Text = strReader.ReadLine() & "<br />"
Dim WriteBuffer(1023) As Byte
Dim enc As ASCIIEncoding = New System.Text.ASCIIEncoding()
WriteBuffer = enc.GetBytes("USER " & "testemail.email5" & Constants.vbCrLf)
netStream.Write(WriteBuffer, 0, WriteBuffer.Length)
RichTextBox1.Text += strReader.ReadLine() & "<br />"
WriteBuffer = enc.GetBytes("PASS " & "testpassword" & Constants.vbCrLf)
netStream.Write(WriteBuffer, 0, WriteBuffer.Length)
RichTextBox1.Text += strReader.ReadLine() & "<br />"
WriteBuffer = enc.GetBytes("LIST" & Constants.vbCrLf)
netStream.Write(WriteBuffer, 0, WriteBuffer.Length)
Dim ListMessage As String
Do
ListMessage = strReader.ReadLine()
If ListMessage = "." Then
Exit Do
Else
RichTextBox1.Text += ListMessage & "<br />"
Continue Do
End If
Loop
WriteBuffer = enc.GetBytes("QUIT" & Constants.vbCrLf)
netStream.Write(WriteBuffer, 0, WriteBuffer.Length)
RichTextBox1.Text += strReader.ReadLine() & "<br />"
End Sub
End Class