开发者

reading pop3 emails, why not getting read emails?

开发者 https://www.devze.com 2023-03-23 06:08 出处:网络
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 unrea

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 differe开发者_开发技巧ntly. Please guide me how I can do it.

thanks


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.


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;
    }
}


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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号