如何从Imapclient文件夹中获取所有消息?

时间:2015-07-30 01:50:45

标签: c# email imap mime

我打算将所有邮件都放在收件箱文件夹中并将它们放入datagridview组件中。但是这句话是" var message = client.Inbox.GetMessage(uids.Count - i - 1);&#34 ;抛出异常:IMAP服务器未返回请求的消息。我的代码有什么问题吗?

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

1 个答案:

答案 0 :(得分:0)

找出问题的唯一方法是按照MailKit FAQ中的说明获取协议日志,并查看服务器发送的内容作为回复。