PDA

Click to See Complete Forum and Search --> : [RESOLVED] POP3 Email Reader


Jumpercables
Apr 30th, 2006, 05:36 PM
I am trying to write a class to read email from a pop3 server and I am trying to read information from my gmail account. But everytime I get to the line indicated I get the following error I am not sure how to combat this problem.


"Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host."

Here is the code I am trying to make the initial connection.

Private _Server As TcpClient
Private _NetStrm As NetworkStream
Private _ReadStrm As StreamReader
Private _IncommingData As Byte()
Private _Password as String
Private _Username as String
Private Const CRLF As String = vbCrLf

Public Function Connect() As Boolean
' create server POP3 with port 110
_Server = New TcpClient("pop.gmail.com", 110)

Try
_NetStrm = _Server.GetStream()
_ReadStrm = New StreamReader(_Server.GetStream())

'Login Process
Dim Data As String = "USER " & _Username & CRLF

_IncommingData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
_NetStrm.Write(_IncommingData, 0, _IncommingData.Length)

Data = "PASS " & _Password & CRLF
_IncommingData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
_NetStrm.Write(_IncommingData, 0, _IncommingData.Length)'Error Here

'Send STAT command to get information ie: number of mail and size
Data = "STAT" + CRLF
_IncommingData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
_NetStrm.Write(_IncommingData, 0, _IncommingData.Length)

Catch ex As Exception
Return False
End Try
Return True
End Function


Thanks In Advance

Mike Stefanik
May 1st, 2006, 07:37 PM
Unless they've recently changed things, GMail requires that you use a secure (SSL/TLS) connection. They also require implicit SSL and don't support the STLS command, which means it doesn't support secure connections over the standard port 110; you have to connect on port 995.

Jumpercables
May 1st, 2006, 10:49 PM
Hmm let me give that a wing

Jumpercables
May 1st, 2006, 11:05 PM
Oh that is fantastic thanks Mike

This bit of extra code made it work along with port change


_Strm = New Net.Security.SslStream(_Server.GetStream())
DirectCast(_Strm, Net.Security.SslStream).AuthenticateAsClient(_PopServ)