Hi Guys,
I have successfully connected to a pop3 server using the code:
It returns back -OK and shows me the number of messages to retieve using the STAT command, I think i need to use the LIST command next, i'm trying to initially display the emails in a listview listeview1 but i'm stuck as to proceed lol
any help would be great!
thanks guys
Graham
I have successfully connected to a pop3 server using the code:
Code:
Private Function SendCommand(ByRef pNetStream As NetworkStream, ByVal pstrCommand As String) As String
Try
Dim strCommand = pstrCommand + vbCrLf
Dim bteCommand() As Byte = Encoding.ASCII.GetBytes(strCommand)
Dim myStreamReader As StreamReader
Dim strLine As String
pNetStream.Write(bteCommand, 0, bteCommand.Length)
myStreamReader = New StreamReader(pNetStream)
strLine = myStreamReader.ReadLine()
Return strLine
Catch ex As Exception
Return ex.Message
End Try
End Function
Private Sub btnDownloadEmails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownloadEmails.Click
'// SETUP THE TCPCLIENT
Dim myTcpClient As New TcpClient()
Dim myNetworkStream As NetworkStream
Try
Dim strReturnMessage As String
'// CONNECT
myTcpClient.Connect(txtBoxMailServer.Text, Integer.Parse(txtBoxPort.Text))
myNetworkStream = myTcpClient.GetStream()
Dim myStreamReader As New StreamReader(myNetworkStream)
'// BUILD THE STRING TO SEND TO THE SERVER
strReturnMessage = myStreamReader.ReadLine() + vbCrLf
strReturnMessage += SendCommand(myNetworkStream, "USER " + txtBoxUsername.Text) + vbCrLf
strReturnMessage += SendCommand(myNetworkStream, "PASS " + txtBoxPassword.Text) + vbCrLf
strReturnMessage += SendCommand(myNetworkStream, "STAT " + txtBoxPassword.Text) + vbCrLf
strReturnMessage += SendCommand(myNetworkStream, "LIST " + vbCrLf)
MessageBox.Show(strReturnMessage)
Catch ex As Exception
'// RETURN ANY ERRORS
MessageBox.Show(ex.Message)
End Try
End Sub
any help would be great!
thanks guys
Graham