无法使用OpenPop.Net从Gmail帐户中删除收件箱邮件

时间:2014-09-23 07:56:43

标签: openpop gmail-pop

我正在使用OpenPop DLL,它对我的​​项目非常有用,但是当我使用Gmail帐户时,我遇到了问题。我在阅读后无法从Gmail中删除电子邮件。我正在使用以下代码和最新的OpenPop DLL:

                using (OpenPop.Pop3.Pop3Client pop3Client = new OpenPop.Pop3.Pop3Client())
                {
                    // Connect to the server
                    pop3Client.Connect(
                        ConfigurationManager.AppSettings["host"],
                        Convert.ToInt32(ConfigurationManager.AppSettings["port"]),
                        Convert.ToBoolean(ConfigurationManager.AppSettings["useSsl"]));

                    // Authenticate ourselves towards the server
                    pop3Client.Authenticate(
                        ConfigurationManager.AppSettings["username"],
                        ConfigurationManager.AppSettings["password"],
                        AuthenticationMethod.UsernameAndPassword);

                    // Get the number of messages in the inbox
                    int messageCount = pop3Client.GetMessageCount();
                    if (messageCount > 0)
                    {
                        // We want to download all messages
                        allMessages = new List<Message>(messageCount);

                        // Messages are numbered in the interval: [1, messageCount]
                        // Ergo: message numbers are 1-based.
                        // Most servers give the latest message the highest number
                        for (int i = messageCount; i > 0; i--)
                        {
                            allMessages.Add(pop3Client.GetMessage(i));
                        }

                        // Process all the messages and save in database
                    }
                    // On successful insert in database, delete the same message from email server
                    pop3Client.DeleteAllMessages();
                    pop3Client.Disconnect();
                    pop3Client.Dispose();
                }

如果我在代码中做错了,你能告诉我吗?你的帮助会很明显。

0 个答案:

没有答案