Fetched Emails not ordered when I use pop3

 ̄綄美尐妖づ 提交于 2019-12-11 20:41:31

问题


First I were Fetching emails by POP3 using this library OpenPop.Pop3 and it was working ok and it was returns emails ordered from last email to first email but when I change the library to mailkit library the returned messages not ordered and couldn't know based on what mailkit order fetched emails that's my code after I change to mailkit library

using (Pop3Client client = new Pop3Client())
        {
            // Connect to the server
            client.Connect(hostname, port, useSsl);
            client.AuthenticationMechanisms.Remove("XOAUTH2");
            client.Authenticate((username), password);
            int messageCount = client.Count;

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

            for (int i = messageCount-1; i > 0; i--)
            {
                    var msg = client.GetMessage(i);
                    allMessages.Add(msg);
            }
         }

by this way allmessages variable should contains emails ordered from last email to first email but that's not happened emails not ordered at all although I were using the same authenticated email before with OpenPop.Pop3 and fetched emails were ordered


回答1:


I don't know why they wouldn't be ordered for you since MailKit is not doing any kind of sorting.

That said, MailKit uses 0-based indexes while I suppose OpenPOP.NET must have used 1-based indexes, so your loop should make the following change:

for (int i = messageCount-1; i >= 0; i--)
{
    var msg = client.GetMessage(i);
    allMessages.Add(msg);
}

Perhaps this will produce the expected results?

Update: It turns out that MailKit was correctly downloading the messages in reverse order just as his code was trying to do (as mentioned in his follow-up question). The problem this user was facing is that his GMail account settings were only providing MailKit's Pop3Client with a subset of his total Inbox as is explained in Google's FAQ in the section titled "Emails aren't downloading correctly", where it states:

After you set up POP in your Gmail settings, your emails become available in batches. It might take a while to see all your emails.

Note: Gmail downloads a copy of every email you send or receive, except for emails in Chats, Spam, and Trash. To avoid duplicates, Gmail doesn't download emails sent within your mail client, but you can still see them if you log in to Gmail.

If you continue to have problems downloading emails, try using recent mode:

  1. In your email client's POP settings page, find the "Email address" or "User name" field.
  2. Add recent: in front of your email address. For example, recent:example@gmail.com.

If that doesn't fix the problem, try deleting your Gmail address from your email client, then re-adding it.



来源:https://stackoverflow.com/questions/53303349/fetched-emails-not-ordered-when-i-use-pop3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!