如何使用pop3检索未读的电子邮件?

Amr*_*har 6 pop3

我使用开源组件来检索使用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
Run Code Online (Sandbox Code Playgroud)

如果我以错误的方式使用组件,或者如果有另一个组件做我正在寻找的东西,我需要一些帮助.bs:我的组件名称是"Higuchi.Mail.dll"或"OpenPOP.dll",两者相同.

谢谢

js1*_*568 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
Run Code Online (Sandbox Code Playgroud)

只需让程序将值更改为startItem50 即可获得下一个五十(项目 50-100)