可以尝试以下代码示例解决此问题:
using (ImapClient client = new ImapClient())
{
client.Connect("imap.gmail.com", 993, true);
client.Authenticate("user@gmail.com", "password");
client.Inbox.Open(FolderAccess.ReadOnly);
var uids = client.Inbox.Search(SearchQuery.NotSeen);
foreach (var uid in uids)
{
var message = client.Inbox.GetMessage(uid);
// do something with the message
}
client.Disconnect(true);
}
其中,使用搜索查询NotSeen来检查未读邮件是否可见,如果可见,则将其添加到UID列表中。可以使用循环遍历UID列表并获取该邮件的详细信息。