如何使用pop3 c#阅读最新的电子邮件

How to read latest email using pop3 c#

我想通过我的 gmail 帐户阅读 emial。 我正在使用 "OpenPop.Pop3" 从我的 gmail 帐户读取电子邮件,我正在使用以下代码:-

using OpenPop.Pop3;    
public DataTable ReadEmailsFromId()
        {
            DataTable table = new DataTable();
            try
            {
                using (Pop3Client client = new Pop3Client())
                {
                    int messageCount = client.GetMessageCount();
                    for (int i = messageCount; i > 0; i--)
                    {
                        table.Rows.Add(client.GetMessage(i).Headers.Subject, client.GetMessage(i).Headers.DateSent);
                        string msdId = client.GetMessage(i).Headers.MessageId;
                        OpenPop.Mime.Message msg = client.GetMessage(i);
                        OpenPop.Mime.MessagePart plainTextPart = msg.FindFirstPlainTextVersion();
                        string message = plainTextPart.GetBodyAsText();                           
                    }
                }
            }
        return table;
        }

但它提取的是 2016 年 3 月 4 日之前的电子邮件,而不是提取 new/latest 封电子邮件。 "OpenPop.Pop3" 中有任何限制还是我遗漏了什么?

通过 POP3 的 Gmail 有一些怪癖。试试这些链接,看看它们是否有帮助。

Get latest mail from the mail server using OpenPop

What non-standard behaviour features does Gmail exhibit, when it is programmatically used as a POP3 server?

要获取新电子邮件,只需在用户名前输入关键字 "recent:",然后它将提供过去 30 天内收到的电子邮件。

 using OpenPop.Pop3;    
    public DataTable ReadEmailsFromId()
    {
        DataTable table = new DataTable();
        try
        {
            using (Pop3Client client = new Pop3Client())
            {
                client.Connect("pop.gmail.com", 995, true); //For SSL                
                client.Authenticate("recent:Username", "Password", AuthenticationMethod.UsernameAndPassword);

                int messageCount = client.GetMessageCount();
                for (int i = messageCount; i > 0; i--)
                {
                    table.Rows.Add(client.GetMessage(i).Headers.Subject, client.GetMessage(i).Headers.DateSent);
                    string msdId = client.GetMessage(i).Headers.MessageId;
                    OpenPop.Mime.Message msg = client.GetMessage(i);
                    OpenPop.Mime.MessagePart plainTextPart = msg.FindFirstPlainTextVersion();
                    string message = plainTextPart.GetBodyAsText();                           
                }
            }
        }
    return table;
    }