使用pop3时未排序提取的电子邮件 [英] Fetched Emails not ordered when I use pop3

查看:323
本文介绍了使用pop3时未排序提取的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我正在使用该库OpenPop.Pop3通过POP3提取电子邮件,并且工作正常,并且将从最后一封电子邮件订购的电子邮件返回到第一封电子邮件 但是,当我将库更改为mailkit库时,返回的邮件未排序,并且基于哪个mailkit订单无法获取邮件 这是我更改为Mailkit库后的代码

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

通过这种方式,allmessages变量应该包含从最后一封电子邮件到第一封电子邮件排序的电子邮件,但是这完全没有发生 尽管我之前使用的是与OpenPop.Pop3相同的经过身份验证的电子邮件,并且已订购提取的电子邮件

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

推荐答案

我不知道为什么为什么不为您订购它们,因为MailKit没有进行任何排序.

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

也就是说,MailKit使用基于0的索引,而我认为OpenPOP.NET必须使用基于1的索引,因此您的循环应进行以下更改:

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?

更新:事实证明,MailKit正确地以相反的顺序下载了消息,就像他的代码试图这样做一样(如他的常见问题解答在标题为电子邮件下载不正确"的部分中,指出:

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:

在Gmail设置中设置POP后,您的电子邮件将可用 分批.可能需要一段时间才能看到您的所有电子邮件.

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.

注意:Gmail会下载您发送或接收的每封电子邮件的副本,但 用于聊天",垃圾邮件"和已删除邮件"中的电子邮件.为避免重复,Gmail不会 下载在您的邮件客户端中发送的电子邮件,但是您仍然可以看到它们 如果您登录到Gmail.

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. 在电子邮件客户端的POP设置页面中,找到电子邮件地址"或 用户名"字段.
  2. 添加最新消息:在您的电子邮件地址之前.例如, 最近:example@gmail.com.
  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.

如果仍不能解决问题,请尝试从电子邮件客户端中删除您的Gmail地址,然后重新添加.

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

这篇关于使用pop3时未排序提取的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆