+1 vote

I am using POP3 to receive emails. I already used IMAP to receive unread emails using flag.unseen and it is working. But I want to achieve same using POP3. It would be great if you can suggest some way for this.

I have to use POP3 now to receive and read only unread emails. For example, for some of my email IDs I can use POP3 and for some IMAP so my application should be able to use both server.

Kindly guide for the same.

Thanks.

by

1 Answer

0 votes

POP3 protocol does not have a concept on unread messages.

You have to mark which message has been read by yourself on the client application.

Below is an example that downloads email messages using POP3. You must provide your own WasReceived method implementation, which checks if specified uid was already processed and stores this uid if it wasn't:

using (Pop3 pop3 = new Pop3())
{
    pop3.Connect("pop3.example.com");
    pop3.Login("user", "password");

    MailBuilder builder = new MailBuilder();
    foreach (string uid in pop3.GetAll())
    {
        Console.WriteLine("Message unique-id: {0};", uid);

        if (WasReceived(uid) == true)
            continue;

         IMail email = builder.CreateFromEml(
             pop3.GetMessageByUID(uid));

         Console.WriteLine(email.Subject);
         Console.WriteLine(email.Text);
     }
     pop3.Close();
}


private static bool WasReceived(string uid)
{
    // Here you should check if this uid was already received.
    // Store this uid for future reference if it wasn't.
    throw new NotImplementedException();
}

If you are using Gmail make sure you understand how Gmail's POP3 works:
https://www.limilabs.com/blog/gmail-pop3-behavior

by (297k points)
...