我正在使用此代碼連接到使用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