如何使用mailkit为消息分配类别

问题描述 投票:0回答:2

我正在使用 mailkit 从基于 UID (IMAP) 的收件箱读取电子邮件,效果很好。但是,我没有找到以编程方式使用 mailkit 将类别设置为电子邮件的选项。

我确实看到了使用以下代码设置自定义标志的选项。然而,这似乎不起作用,因为我们无法可视化电子邮件的状态。

var customFlags = new HashSet<string>();
                customFlags.Add("$Testing");
inbox.AddFlags(UniqueId.Parse(uid), MessageFlags.None, customFlags, true);

我正在寻找有关如何仅使用 mailkit 将以下类别设置为电子邮件消息的信息。

客户端:Imap,
邮箱:O365

c# email mailkit
2个回答
0
投票

IMAP 没有类别或样式的概念。

这取决于用户的邮件客户端,通过在消息上设置自定义标志(假设 IMAP 服务器支持自定义标志)或仅以某种方式将这些属性存储在用户桌面(或移动设备)本地来进行合成。


0
投票

正如 Jazb 所说,IMAP 没有“类别”的概念,客户端需要寻找存储此状态的替代方法。

我不确定 Office365 是否支持存储自定义关键字(又名自定义标志),但您可以做的是创建一个测试文件夹,并在该文件夹中添加 6 条消息,每个类别 1 条,为它们提供主题轻松提示您为每个人分配哪个类别(例如“主题:蓝色类别”)。

然后使用 MailKit 获取

MessageSummaryItems.Flags | MessageSummaryItems.Envelope
数据:

var items = folder.Fetch (0, -1, MessageSummaryItems.Flags | MessageSummaryItems.Envelope);
foreach (var item in items) {
    Console.WriteLine ("Office365 uses the {0} keyword to designate the {1}", item.Keywords.FirstOrDefault (), item.Envelope.Subject);
}

您将得到如下输出:

Office365 uses the $MailLabel1 keyword to designate the Blue category
Office365 uses the $MailLabel2 keyword to designate the Green category
Office365 uses the $MailLabel3 keyword to designate the Orange category
Office365 uses the $MailLabel4 keyword to designate the Purple category
Office365 uses the $MailLabel5 keyword to designate the Red category
Office365 uses the $MailLabel6 keyword to designate the Yellow category

一旦您知道关键字的真实名称(可能是也可能不是“$MailLabel1”),那么您可以通过以下方式设置关键字:

var keywords = new HashSet<string> () { "$MailLabel1" };
folder.AddFlags (uid, MessageFlags.None, keywords, true);
© www.soinside.com 2019 - 2024. All rights reserved.