Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2010 Connected to pop3 now to retrieve

$
0
0
Hi Guys,

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

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

Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>