我正在使用开源组件使用vb.net从我的邮件服务器检索电子邮件(pop3) 但是因为我有很多消息,它给了我响应超时,我想如果我刚收到新消息,它将使阅读更快。 这是我的代码:
Dim popp As New Pop3Client("user@mail.com", "*******", "pop3.mail.com")
popp.AuthenticateMode = Pop3AuthenticateMode.Pop
popp.Port = 110
'popp.Ssl = True
popp.Authenticate()
Dim msglist As New List(Of String)
If popp.State = Pop3ConnectionState.Authenticated Then
Dim totalmsgs As Integer = popp.GetTotalMessageCount()
If totalmsgs > 0 Then
For index As Integer = 1 To totalmsgs
Dim msg As Pop3Message = popp.GetMessage(index)
msglist.Add(msg.Subject)
Next
popp.Close()
End If
End If
Return msglist
如果我以错误的方式使用该组件,或者如果有其他组件做我正在寻找的组件,那么我需要一些帮助。 理学士:我的组件名称是“Higuchi.Mail.dll”或“OpenPOP.dll”,两者相同。
感谢
答案 0 :(得分:4)
POP3无法跟踪邮件是已读取还是未读取。我建议你将限制设置为有限数,例如50或100.也许你可以做某种分页系统。
此代码需要在函数内,以便您可以这样调用它:
Sub Main
Dim start As Integer = Integer.parse(Request.QueryString("start"))
Dim count As Integer = Integer.parse(Request.QueryString("count"))
Dim subjects As New List(Of String)
subjects = getSubjects(start, count)
'Do whatever with the results...
'
End Sub
Function getSubjects(ByVal startItem As Integer, ByVal endItem as Integer) As List(Of String)
Dim popp As New Pop3Client("user@mail.com", "*******", "pop3.mail.com")
popp.AuthenticateMode = Pop3AuthenticateMode.Pop
popp.Port = 110
popp.Authenticate()
Dim msglist As New List(Of String)
If popp.State = Pop3ConnectionState.Authenticated Then
Dim totalmsgs As Integer = popp.GetTotalMessageCount()
Dim endItem As Integer = countItems + startItem
If endItem > totalmsgs Then
endItem = totalmsgs
End If
If totalmsgs > 0 Then
For index As Integer = startItem To endItem
Dim msg As Pop3Message = popp.GetMessage(index)
msglist.Add(msg.Subject)
Next
popp.Close()
End If
End If
Return msglist
End Function
让程序将startItem
的值更改为50以获得接下来的50(项目50-100)
答案 1 :(得分:1)
POP3协议没有看到/看不见的消息的概念。
你不能使用 IMAP 吗?
它会为您提供比POP3更多的功能(如搜索,标记,文件夹管理)。