The POP3 protocol does not have any knowledge of unread emails on the server. That information is never presented in the protocol.
Therefore it is not possible to see if someone has read the email already.
A common solution is to keep the unique ID's of each email that has been read at the side of the Pop3Client.
The example below shows you how you might code this up. To start with, you can supply an empty list of UIDs seen, and
all messages on the server will be downloaded.
Next time you pass it the same list, which now has all the previously downloaded message UIDs, and the method will now not download these.
/// <summary>
/// Example showing:
/// - how to use UID's (unique ID's) of messages from the POP3 server
/// - how to download messages not seen before
/// (notice that the POP3 protocol cannot see if a message has been read on the server
/// before. Therefore the client need to maintain this state for itself)
/// </summary>
/// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
/// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
/// <param name="useSsl">Whether or not to use SSL to connect to server</param>
/// <param name="username">Username of the user on the server</param>
/// <param name="password">Password of the user on the server</param>
/// <param name="seenUids">
/// List of UID's of all messages seen before.
/// New message UID's will be added to the list.
/// Consider using a HashSet if you are using >= 3.5 .NET
/// </param>
/// <returns>A List of new Messages on the server</returns>
public static List<Message> FetchUnseenMessages(string hostname, int port, bool useSsl, string username, string password, List<string> seenUids)
{
// The client disconnects from the server when being disposed
using(Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostname, port, useSsl);
// Authenticate ourselves towards the server
client.Authenticate(username, password);
// Fetch all the current uids seen
List<string> uids = client.GetMessageUids();
// Create a list we can return with all new messages
List<Message> newMessages = new List<Message>();
// All the new messages not seen by the POP3 client
for(int i = 0; i<uids.Count; i++)
{
string currentUidOnServer = uids[i];
if (!seenUids.Contains(currentUidOnServer))
{
// We have not seen this message before.
// Download it and add this new uid to seen uids
// the uids list is in messageNumber order - meaning that the first
// uid in the list has messageNumber of 1, and the second has
// messageNumber 2. Therefore we can fetch the message using
// i + 1 since messageNumber should be in range [1, messageCount]
Message unseenMessage = client.GetMessage(i + 1);
// Add the message to the new messages
newMessages.Add(unseenMessage);
// Add the uid to the seen uids, as it has now been seen
seenUids.Add(currentUidOnServer);
}
}
// Return our new found messages
return newMessages;
}
}
One protocol that does have the read state of the emails is the IMAP protocol.