【发布时间】:2011-01-14 19:44:58
【问题描述】:
我正在使用此代码通过 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
当我使用 top 而不是 retr 时,我得到了这个
+OK X-MimeOLE: Produced By Microsoft Exchange V6.5 Received: by xch0p.com id <01CB58CE.A6A4EA@p.com>; 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: <58BFAFC0B9884245A005DFC0C3F73B8604188DF0@abc-exch01.rp.com> 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 而不是做低级网络流?
-
6.5 我不确定我是新手
-
你的代码实际上对我来说很好用。你收到错误了吗。你能告诉我们什么是“胡言乱语”吗?我没有交换服务器来对其进行测试,但我对其进行了测试,但由于您只是使用 POP3,这并不重要。
-
它工作正常,但在这种情况下它只返回一条消息,这是我希望它只返回最后 10 条消息的第一条消息。而不是整个邮件只是发件人以及主题和日期
-
其实我用imap4可能会更好,还是没关系
标签: asp.net vb.net exchange-server pop3