1

I'm reading emails from my web domain in C# and using OpenPop.net library.

It is reading email but it only get emails that are new. I want to make it like hotmail that it should fetch read and unread both then using CSS I will display them differently. Please guide me how I can do it.

thanks

Onots
  • 2,118
  • 21
  • 28
user576510
  • 5,777
  • 20
  • 81
  • 144

4 Answers4

2

POP3 is not a storage system like IMAP.

When you get mail from POP3 it normally deletes the email from the server (forever). That's just how it works.

Perhaps there is an option in OpenPOP that allows one not to delete the emails on the server after retrieval.

leppie
  • 115,091
  • 17
  • 196
  • 297
  • Thanks leppie, can u plz guide what is that option ? I want to keep emails for retriving next as well. Thanks – user576510 Jul 28 '11 at 07:14
  • The pop3 protocol doesn't delete messages after they're retrieved. Most clients delete messages from the server once the message has been downloaded. (the pop3 DELE command is used) – Onots Jul 28 '11 at 07:22
  • 3
    I am a developer for OpenPop. The library does not delete an email when it has been received - if this is done, you have to use the DeleteMessage method. Some servers can CHOOSE to delete (or hide) the emails that has been fetched by some POP3 client. Gmail is one such service. Try using the CAPA(bility) command and see the [EXPIRE tag](http://tools.ietf.org/html/rfc2449#page-10). If CAPA is implemented on the server, this should tell you what happens when you fetch an email. – foens Jul 28 '11 at 09:24
2

Edit:

I'm guessing you're trying to retrieve mail from gmail using their POP3. Gmail has some weird non-standard POP3 behaviour. Gmail will hide messages that have been retrieved and ignores the POP3 DELE command. See this related question for more information on this behaviour.

One of the Openpop examples shows how to retrieve all messages:

/// <summary>
/// Example showing:
///  - how to fetch all messages from a POP3 server
/// </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>
/// <returns>All Messages on the POP3 server</returns>
public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
    // 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);

        // Get the number of messages in the inbox
        int messageCount = client.GetMessageCount();

        // We want to download all messages
        List<Message> allMessages = new List<Message>(messageCount);

        // Messages are numbered in the interval: [1, messageCount]
        // Ergo: message numbers are 1-based.
        for(int i = 1; i <= messageCount; i++)
        {
            allMessages.Add(client.GetMessage(i));
        }

        // Now return the fetched messages
        return allMessages;
    }
}
Community
  • 1
  • 1
Onots
  • 2,118
  • 21
  • 28
1

Because the POP standard-behaviour is:

  • download message
  • delete message

while the IMAP standard-behaviour is:

  • download message
  • leave message there

You can always alter that behavior, given your POP library is sufficiently low-level.

Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
  • It is standard client behaviour to delete messages after retrieving them. But the client uses RETR (id) to get the message and DELE (id) to delete it. Deleting retrieved messages is not enforced in any way, or am I mistaking? – Onots Jul 28 '11 at 07:30
0

What you could do is write all emails to a database when you fetch them from the smtp server, so next time you open your application you can still read the all emails.

Usually mail servers delete the mail when a client has received it (in outlook, and other mail clients, there is a specific setting to turn this on/off, maybe OpenPop lib also has a setting for this)

Thomas
  • 595
  • 1
  • 5
  • 20
  • I disagree with this answer. Email servers CAN delete email when received by a client, but this is optional. There is NO way for the POP3 client to disable/enable this, ergo no option to turn this on/off. The option that can be turned off, is to send the DELE command after the RETR command - ergo turning off the client deleting the email just fetched from the server. This is really not the same! – foens Jul 28 '11 at 09:16