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

asked 15 Jul '10, 00:36

Quotient's gravatar image

Quotient
16
accept rate: 0%


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.

link

answered 15 Jul '10, 10:19

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310
accept rate: 37%

edited 16 Jul '10, 11:44

Lukas%20Matyska's gravatar image

Lukas Matyska ♦♦
78217

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×33
×1

Asked: 15 Jul '10, 00:36

Seen: 345 times

Last updated: 25 Mar '11, 23:22