0 votes
by (260 points)
edited

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
by (62.7k points)
edited

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)

...