Free Support Forum - aspose.com

Read only Unread email or latest email using pop3 c#

I want to read only unread emails using pop3.I have done this with imap
but now i also want this with pop3. I dont want that each time download
email and save it to local database and compare it for next time. I want
directly unread email from server using pop3.

or is there any way in pop3 for new email notification like outlook uses using pop3. ?

Hi,


Thank you for writing to Aspose support team.

Retrieving only unseen/unread messages is not possible using POP3 protocol and there is no way to mark which message was recieved by the client application. In order to achieve this, you can write your own logic to mark the retrieved messages with its UniqueId and store this information in your database for checking next time as shown in the following code sample. Please let us know if we can be of any additional help to you in this regard.

Sample Code:

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:blue;mso-no-proof:yes”>static void<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”>
Pop3UnreadMessages()<o:p></o:p>

{

Pop3Client client = newPop3Client("pop.gmail.com", 995, "username", "password");

client.EnableSsl = true;

Pop3MessageInfoCollection msgs = client.ListMessages();

Console.WriteLine(msgs.Count);

foreach (Pop3MessageInfo msgInfo in msgs)

{

if (IsProcessed(msgInfo.UniqueId)) //means the message was already processed

{

continue;

}

//message is new and needs user attention

//Handle the unaddressed messages as per your requiremetnts

MailMessage msg = client.FetchMessage(msgInfo.UniqueId);

}

}

static bool IsProcessed(string UniquedId)

{

//check the email in processed list and return true or false accordingly

return true;

}