I'm trying to collect (yahoo,gmail,hotmail etc.,)inbox mails uding vb.net?
i tried this using tcpclient,
First i got the tcpclient connection,and get response data from server for
(gmail --host--> "pop.gmail.com") got response like
"+OK Gpop ready for requests from 122.174.183.249 b15pf3378725rvn.27"
second,i'm trying to get response data from server for my username and password
it shows message
"Unable to read data from the transport connection:
An established connection was aborted by the software in your host machine."
code :
Public Sub Authenticate()
If Open() = Pop3ConnectionState.Connected Then
AuthenticateByPop()
End If
End Sub
Public Function Open() As Pop3ConnectionState zTcpClient = Me.GetTcpClient() If zTcpClient Is Nothing Then Me.zState = Pop3ConnectionState.Disconnected Else Dim str As Stream = zTcpClient.GetStream If Me.zSsl = True Then
Dim bssl As New SslStream(zTcpClient.GetStream, False, Me.RemoteCertificateValidationCallback, Nothing)
bssl.AuthenticateAsClient(Me.zServerName)
zStream = bssl
Else
zStream = zTcpClient.GetStream()
End If
zReader = New StreamReader(zStream, Encoding.ASCII)
If Me.GetResponse(True).StartsWith("+OK") = True Then
Me.zState = Pop3ConnectionState.Connected
Else
zTcpClient = Nothing
Me.zState = Pop3ConnectionState.Disconnected
End If
End If
Return Me.zState
End Function
Private Function GetTcpClient() As TcpClient Dim tc As TcpClient = Nothing
Dim hostEntry As IPHostEntry = Nothing
Try
' Get IP address list from host server.
hostEntry = Dns.GetHostEntry(Me.zServerName)
' Create socket with confirm IP address is valid.
For Each address As IPAddress In hostEntry.AddressList
' Dim add As Long = "74.125.43.18"
' Dim ip As New IPEndPoint(address, 995)
Dim ipe As New IPEndPoint(address, 995)
tc = New TcpClient(ipe.AddressFamily)
tc.Connect(ipe)
If tc.Connected Then
tc.ReceiveTimeout = Me.zReceiveTimeout
tc.ReceiveBufferSize = Me.zReceiveBufferSize
Return tc
End If
Next
Catch
End Try
If tc Is Nothing Then
Me.zState = Pop3ConnectionState.Disconnected
Return Nothing
End If
Me.zState = Pop3ConnectionState.Connected
Return tc
End Function
Private Function GetResponse(ByVal inIsMultiLine As [Boolean]) As [String] If zTcpClient Is Nothing Then MsgBox("Connection to POP3 server is closed") 'Throw New Pop3ConnectException("Connection to POP3 server is closed") End If Dim dtime As DateTime = DateTime.Now Dim ts As TimeSpan Dim sb As New StringBuilder() Dim CurrentLine As [String] = "" Dim LineIndex As Int64 = 0
While True
ts = DateTime.Now - dtime
'If ts.TotalMilliseconds < Me.zReceiveTimeout Then
' MsgBox("Response timeout")
' Exit While
' 'Throw New Pop3ReceiveException("Response timeout")
'End If
'''wait response until be able to read data.
Me.ThreadSleep(zThreadSleepMilliseconds)
CurrentLine = zReader.ReadLine()
sb.AppendLine(CurrentLine)
LineIndex += 1
If Not CurrentLine Is Nothing Then
If CurrentLine.StartsWith("+OK") Then
inIsMultiLine = False
End If
End If
'''if multi line mode,continue execution.if single line mode,finish execution.
If inIsMultiLine = False Then
Exit While
End If
'''If only period line,finish execution.
If CurrentLine = "." Then
Exit While
End If
End While
Me.zCommnicating = False
Return sb.ToString()
End Function
Public Function AuthenticateByPop() As [Boolean] Dim s As [String] = ""
' If Me.EnsureOpen() = Pop3ConnectionState.Connected Then
If Pop3ConnectionState.Connected Then
' send user name
s = Me.Execute("user " & Me.zUserName, False)
'check response from server
If s.StartsWith("+OK") = True Then
'send password with clear text
s = Me.Execute("pass " & Me.zPassword, False)
'check authentication result
If s.StartsWith("+OK") = True Then
Me.zState = Pop3ConnectionState.Authenticated
End If
End If
End If
Return Me.zState = Pop3ConnectionState.Authenticated
End Function
Private Function Execute(ByVal inCommand As [String], ByVal inIsMultiLine As [Boolean]) As [String] Me.SendCommand(inCommand) Me.zCommnicating = True Return Me.GetResponse(inIsMultiLine) End Function
how can i solve this? Please help me.