【问题标题】:How to get all the messages from the Imapclient folder?如何从 Imapclient 文件夹中获取所有消息?
【发布时间】:2015-10-21 05:34:00
【问题描述】:

我本来打算把我所有的消息都放在Inbox文件夹里,放到datagridview组件中。但是一句“var message = client.Inbox.GetMessage(uids.Count - i - 1);”抛出异常: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();
}

【问题讨论】:

  • 请为您使用的编程语言添加标签。快速谷歌搜索建议使用 VB.NET 或 C#,但这看起来也不像。

标签: c# email imap mime


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-10
    相关资源
    最近更新 更多