'Command "list "inbox" "*"" failed' 同时使用 MailSystem.net

'Command "list "inbox" "*"" failed' while using MailSystem.net

我正在尝试使用 MailSystem.Net 从我的 gmail 帐户中检索邮件,但出现上述错误。我似乎没有在 googl 上找到与此类错误相关的任何 link。这是我的代码

public class MailRepository
        {
            private Imap4Client client;
            public MailRepository(string mailServer, int port, bool ssl, string login, string password)
            {
                if (ssl)

                    Client.ConnectSsl(mailServer, port);
                else

                    Client.Connect(mailServer, port);


            }
            public IEnumerable<Message> GetAllMails(string mailBox)
            {
                return GetMails(mailBox, "ALL").Cast<Message>();
            }

            public IEnumerable<Message> GetUnreadMails(string mailBox)
            {
                return GetMails(mailBox, "UNSEEN").Cast<Message>();
            }

            protected Imap4Client Client
            {
                get { return client ?? (client = new Imap4Client()); }
            }

            private MessageCollection GetMails(string mailBox, string searchPhrase)
            {
                Mailbox mails = Client.SelectMailbox(mailBox);
                MessageCollection messages = mails.SearchParse(searchPhrase);
                return messages;
            }
        }

这是我得到的错误:命令 "list "inbox" "*"" 失败:171031010631135 BAD 未知命令 b7mb174701481wmf

 private void ReadImap()
        {
            var mailRespository = new MailUtil.MailRepository("imap.gmail.com", 993, true, "myGmailAccount", "Mypassword");
            var emailList = mailRespository.GetAllMails("inbox");
            foreach(Message email in emailList)
            {
                //DoSomething

                if(email.Attachments.Count > 0)
                {
                    //DoSomething
                }
            }
        }

我做错了什么??我只是出于演示目的复制我在此处在线阅读的内容。

您尝试登录了吗?

您收到该错误似乎是因为您从未登录过,因此 LIST 命令无效。

在您的示例中,您删除了 Client.Login:

    public MailRepository(string mailServer, int port, bool ssl, string login, string password)
    {
        if (ssl)
            Client.ConnectSsl(mailServer, port);
        else
            Client.Connect(mailServer, port);
        Client.Login(login, password); // LINE YOU MISSED
    }