Dolby Xiaowen
Dolby Xiaowen

Reputation: 25

How to get all the messages from the Imapclient folder?

I intended to get all my messages in the Inbox folder and put them into the datagridview component.But the sentence "var message = client.Inbox.GetMessage(uids.Count - i - 1);" throws an exception:The IMAP server did not return the requested message. Is there anything wrong with my code?

//get a imapclient and connect to the server 
string loginemail = UserInfo.LoginEmail;
string password = UserInfo.LoginPassword;
var client = new ImapClient();
client.Connect("imap.qq.com", 993, SecureSocketOptions.SslOnConnect);
client.Authenticate(loginemail, password);
client.Inbox.Open(FolderAccess.ReadOnly);
var uids = client.Inbox.Search(SearchQuery.All);

//get all the messages from the specified folder
 for (int i = 0; i < uids.Count; i++)
 {
    dataGridView1.Rows.Add(1);
    var message = client.Inbox.GetMessage(uids.Count - i - 1);
    dataGridView1.Rows[i].Cells[0].Value = message.From.ToString();
    if (message.Subject != null) { dataGridView1.Rows[i].Cells[1].Value = message.Subject.ToString(); }
    else { dataGridView1.Rows[i].Cells[1].Value = ""; }
    dataGridView1.Rows[i].Cells[2].Value = message.Date.ToString();
}

Upvotes: 1

Views: 5666

Answers (1)

jstedfast
jstedfast

Reputation: 38618

The only way to figure out the problem is to follow the directions in the MailKit FAQ to get a protocol log and look to see what the server is sending as a reply.

Upvotes: 1

Related Questions