How Can we get the recent top 10 emails from POP3?

0 votes
asked Dec 6, 2010 by Reddy (260 points)
edited Mar 29, 2011

Hi all,

We want to get the top 10 recent mails from POP3. How can ws fetch the recent top10 emails form POP3?

Please give me some suggestions....

thanks in advance...

Applies to: Rebex Secure Mail

1 Answer

0 votes
answered Dec 7, 2010 by Lukas Matyska (52,510 points)
edited Dec 7, 2010

Email's sequence number corresponds to the Date it was stored on the POP3 server. Therefore to fetch the recent TOP 10 emails you can simply iterate from the last sequence number (pop3.GetMessageCount()) as follows:

Pop3 pop3 = new Pop3();
// connect and login

int start = pop3.GetMessageCount();
int stop = Math.Max(start - 10, 0);

for (int i = start; i > stop; i--)
{
    MailMessage mail = pop3.GetMailMessage(i);
    Console.WriteLine("{0}: {1}", mail.Date, mail.Subject);
    // ...
}

Please note that sequence numbers run from 1 (not 0)

...