connecting to exchange server

Posted by MyHeadHurts on Stack Overflow See other posts from Stack Overflow or by MyHeadHurts
Published on 2011-01-14T19:44:58Z Indexed on 2011/01/14 19:53 UTC
Read the original article Hit count: 237

Filed under:
|
|
I am using this code to connect to my exchange server.

I am trying to retrieve an inbox of basically emails that have not been read

however, i am just getting a bunch of gibberish and its reading an email.

can you help me modify my code to just read the most recent messages.

 Try
                tcpClient.Connect(hostName, 110)
                Dim networkStream As NetworkStream = tcpClient.GetStream()
                Dim bytes(tcpClient.ReceiveBufferSize) As Byte
                Dim sendBytes As Byte()



                networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))



                sendBytes = Encoding.ASCII.GetBytes("User " + userName + vbCrLf)
                networkStream.Write(sendBytes, 0, sendBytes.Length)



                sTemp = networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))



                sendBytes = Encoding.ASCII.GetBytes("Pass " + userPassword + vbCrLf)
                networkStream.Write(sendBytes, 0, sendBytes.Length)



                sTemp = networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))



                sendBytes = Encoding.ASCII.GetBytes("STAT" + vbCrLf)
                networkStream.Write(sendBytes, 0, sendBytes.Length)



                sTemp = networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))



                sendBytes = Encoding.ASCII.GetBytes("RETR " + messageNumber + vbCrLf)
                networkStream.Write(sendBytes, 0, sendBytes.Length)




                networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
                returnMessage = Encoding.ASCII.GetString(bytes)
                EmailContent.Text = returnMessage



                sendBytes = Encoding.ASCII.GetBytes("QUIT" + vbCrLf)
                networkStream.Write(sendBytes, 0, sendBytes.Length)



                tcpClient.Close()
            Catch ex As Exception
                EmailContent.Text = "Could not retrieve email or your inbox is empty"
            End Try

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about vb.net