我正在使用此代码连接到使用POP3的交换服务器。连接到交换服务器
我试图找回一个基本上没有被阅读的电子邮件的收件箱,但是,我只是得到一堆乱码和它的阅读电子邮件。
你能帮我修改我的代码来阅读最新的消息吗?
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
当我使用上面,而不是RETR我得到这个
+OK X-MimeOLE: Produced By Microsoft Exchange V6.5 Received: by xch0p.com id <[email protected]>; Mon, 20 Sep 2010 09:17:07 -0500 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01CB58CE.81A6A4EA" Content-class: urn:content-classes:message Subject: What we need to do?? Date: Mon, 20 Sep 2010 09:17:07 -0500 Message-ID: <[email protected]> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: What we need to do?? Thread-Index: ActV7LH3Idm5VVuiRXqkVkVTKZy6fgC4Xsmw X-Priority: 1 Priority: Urgent Importance: high Sensitivity: Company-Confidential From: "Mooq" To: "Everyone " .
什么版本的Exchange?你能不能只使用Exchange API而不是做低级网络流? – 2011-01-14 19:48:34