如何标记看不见的上一条未读消息S22.imap

时间:2013-11-27 16:52:33

标签: c# imap

如何从邮箱中读取上次未读邮件,并在将此邮件标记为“未显示”

之后

我使用s22.imap.dll

ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username",
    "My_Password", true, AuthMethod.Login);

// Get a list of unique identifiers (UIDs) of all unread messages in the mailbox.
uint[] uids = Client.Search( SearchCondition.Unseen() );

// Fetch the messages and print out their subject lines.
foreach(uint uid in uids) {
    MailMessage message = Client.GetMessage(uid);

 Console.WriteLine(message.Subject);
}

// Free up any resources associated with this instance.
Client.Dispose();

1 个答案:

答案 0 :(得分:3)

首先获取uid最后一条未读消息:

var lastUid = Client.Search( SearchCondition.Unseen().Last() );

并阅读此消息;

MailMessage message = Client.GetMessage( lastUid );

将此讯息标记为“看不见”:

Client.RemoveMessageFlags( lastUid, null, MessageFlag.Seen );

详情请见:ImapClient.RemoveMessageFlags Method