How to retrieve just unread emails using pop3?
Asked Answered
E

2

6

I'm using open source component to retrieve emails from my mail server using vb.net (pop3) but because i have a lot of messages it gives me response Time out and i think if i just got the new messages it will make reading faster. this is my code:

    Dim popp As New Pop3Client("[email protected]", "*******", "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

please i need some help if i'm using the component in a wrong way or if there is another component do what i'm looking for. b.s. : my component name is "Higuchi.Mail.dll" or "OpenPOP.dll" and the two are same.

thanks

Emersonemery answered 26/8, 2010 at 14:54 Comment(0)
B
4

POP3 does not have the capibility to track whether messages are read or unread. I would suggest you set your limit to a finite number such as 50 or 100. Perhaps you could do some sort of pagination system.

This code needs to be within a function so that you can call it like so:

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("[email protected]", "*******", "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

Just have the program change the value for startItem to 50 get the next fifty (items 50-100)

Burgher answered 26/8, 2010 at 15:13 Comment(2)
could u please give me sample for using paging.Emersonemery
I added the function and an illustration of how to call itBurgher
P
2

POP3 protocol does not have the notion of seen/unseen messages.

Can't you use IMAP?

It would give you more features (like searching, flagging, folder management) than POP3.

Phraseograph answered 4/9, 2010 at 11:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.