编程语言
首页 > 编程语言> > C#-MailKit Imap获取邮件的已读和未读状态

C#-MailKit Imap获取邮件的已读和未读状态

作者:互联网

我正在使用MailKit从Gmail帐户读取邮件.效果很好.但是,我想获取消息状态为是否已读,未读,重要,已加星标等.MailKit是否可能?我似乎找不到任何东西.

这是我的代码:

 var inbox = client.Inbox;
 var message = inbox.GetMessage(4442);//4442 is the index of a message.

 Console.WriteLine("Message Importance : {0}", message.Importance);
 Console.WriteLine("Message Priority : {0}", message.Priority);

重要性和优先级始终返回“正常”.如何查找此消息是否标记为重要?以及如何获取此消息的已读或未读状态?

解决方法:

没有消息属性,因为MimeMessage只是经过解析的原始MIME消息流,而IMAP不在消息流上存储这些状态,而是将它们分别存储.

要获取所需的信息,您需要使用Fetch()方法:

var info = client.Inbox.Fetch (new [] { 4442 }, MessageSummaryItems.Flags | MessageSummaryItems.GMailLabels);
if (info[0].Flags.Value.HasFlag (MessageFlags.Flagged)) {
    // this message is starred
}
if (info[0].Flags.Value.HasFlag (MessageFlags.Draft)) {
    // this is a draft
}
if (info[0].GMailLabels.Contains ("Important")) {
    // the message is Important
}

希望能有所帮助.

标签:mailkit,mimekit,imap,c,asp-net-mvc
来源: https://codeday.me/bug/20191027/1944903.html