0 votes
by (120 points)
edited

What method would i use to go about getting the last 25 mails in a pop account. I want the top 25 opened and unopened. I have been working on a few things but only see that I can get latest 25 unopened but this makes my app seem a bit weird

Thanks

Applies to: Rebex Secure Mail

1 Answer

0 votes
by (13.3k points)
edited

Unfortunately the POP3 protocol doesn't support concept of read/unread messages. It can return only all messages on the mailbox. Some servers may opt to return only unread messages, some would return all messages in the Inbox folder.

The read/unread flag in POP3 client is usually implemented on client: the client has list of message unique ids which has been downloaded and/or read and shows all messages not in list as 'unread'.

If you want to work with unread messages on server you have to use different protocol - such as IMAP. The IMAP protocol know about messages flags and can search for messages with specified flag set. See following code (again using Rebex Mail component):

    Imports Rebex.Mail
    Imports Rebex.Net  
    ...

    Dim server as string = "imapServer"
    Dim username as string = "myUsername"
    Dim password as string = "myPassword"

    ''# create client, connect and log in
    Dim client As new Imap
    client.Connect(server)
    client.Login(username, password)

    ''# select the folder for search operation
    client.SelectFolder("Inbox")

    ''# find unread messages
    Dim messages as new ImapMessageCollection       
    messages = client.Search( _
        ImapSearchParameter.HasFlagsNoneOf(ImapMessageFlags.Seen ) _
    )

    Console.WriteLine ("Found {0} unread messages.", messages.Count)

    ''# list unread messages:
    Dim message As ImapMessageInfo
    For Each message In messages
        Console.WriteLine( _
            "{0} | {1} | {2} | {3}", _
            message.UniqueID, _
            message.From, _
            message.To, _
            message.Subject)
    Next

More info about IMAP searching can be found at "Searching for messages" section in the IMAP tutorial.

Could you update your question and tell us which POP3 server are you using? It might be possible to configure it in such way that it returns all messages via POP3.

...