[英]how to get uid in mailkit?
my code is: 我的代码是:
using (ImapClient client = new ImapClient())
{
// Connect to the server and authentication and then
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadOnly);
int messageCount = inbox.Count - 1;
for (int i = messageCount; i > 0 ; i--)
{
var visitor = new HtmlPreviewVisitor();
MimeMessage message = inbox.GetMessage(i);
message.Accept(visitor);
// how can get uid for this message
}
}
I wand to save uid . 我想拯救你的魔杖。 how can get uid for message ? 怎么能得到消息的uid?
MimeMessage message =inbox.GetMessage(UniqueId.Parse(uid));
The way to get the UID for a particular message using MailKit is to use the Fetch()
method on the ImapFolder
instance and pass it the MessageSummaryItem.UniqueId
enum value. 使用MailKit Fetch()
特定消息的UID的方法是使用ImapFolder
实例上的Fetch()
方法并将其传递给MessageSummaryItem.UniqueId
枚举值。
Typically you'll want to get the UIDs of the messages in the folder before you fetch the actual message(s), like so: 通常,您需要在获取实际消息之前获取文件夹中的消息的UID,如下所示:
// fetch some useful metadata about each message in the folder...
var items = folder.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.Size | MessageSummaryItems.Flags);
// iterate over all of the messages and fetch them by UID
foreach (var item in items) {
var message = folder.GetMessage (item.UniqueId);
Console.WriteLine ("The message is {0} bytes long", item.Size.Value);
Console.WriteLine ("The message has the following flags set: {0}", item.Flags.Value);
}
The Flags
includes things like Seen
, Deleted
, Answered
, etc. The Flagged
flag means that the message has been flagged as "important" by the user. Flags
包括Seen
, Deleted
, Answered
等内容Flagged
标志表示该消息已被用户标记为“重要”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.