+1 vote


I have read many discussions on here but cannot find my answer. Is there a way to know if an email has been read or not? I read that some POP3's will only list unread emails and some shows them all depending if the email was not removed from the server.

What I need to do is view a list of all unread emails and then based on the date I will delete them from the server. I do not want the emails marked as read either for those that are not deleted. Would I use ExamineInbox for this? And then can I delete one based on the date if I want? But can I still tell if the message was still unread or if it was read and kept on server?

If I can do this I will make a purchase. That will be what I need.



1 Answer

0 votes

You can not achieve what you want using POP3 protocol.
POP3 protocol is very limited. In most cases it only returns new messages. When user uses delete command, message is removed and is not available through POP3 again.

Only IMAP offers ability to search, marking/un-marking message as read.

Imap.ExamineInbox selects (opens) INBOX folder in read only mode - most likely you'll not need this method.

Use IMAP protocol (Imap class) use search to find messages and DeleteMessageByUID to delete them.

The code would look more or less like this:

using(Imap imap = new Imap())
    imap.Connect("imap.server.com");  // or ConnectSSL for SSL
    imap.UseBestLogin("user", "password");


    List<long> uids = imap.Search(
            Expression.Before(new DateTime(2014,01,01))


Here you can find more information on how to search IMAP server:

by (298k points)
edited by
Thanks for this answer and help.. So if I used the code example above would that be deleting only new messages still? I see the Flag.seen in your code. Doesn't that mean it is listing emails that has been read? If so, what would I put for ones that has not been seen?

I will try your code today to see how it works.


The code searches for seen messages. To search for unseen use Flag.Unseen (I'll change that in the answer)
Thanks! Hopefully last question here. Does the GetMessageByUID mark the message as read? I saw there is something called GetEnvelopeByUID but it is not in the help file. I wanted to get a list of emails such as their subject for the ones not read rather than deleting at the beginning just for testing.
Imap.GetMessageByUID marks messages as read, you can use Imap.PeekMessageByUID if you don't want to mark them.  Imap.GetEnvelopeByUID and Imap.GetMessageInfoByUID are the correct methods to get subject only (check out this article: https://www.limilabs.com/blog/get-email-information-from-imap-fast).