[英]how to Assign categories to message uisng mailkit
我正在使用 mailkit 從基於 uid (IMAP) 的收件箱中讀取電子郵件,這工作正常。 但是,我沒有找到以編程方式使用 mailkit 將類別設置為電子郵件的選項。
我確實看到了使用以下代碼設置自定義標志的選項。 然而,這似乎不起作用,因為我們無法可視化電子郵件的狀態。
var customFlags = new HashSet<string>();
customFlags.Add("$Testing");
inbox.AddFlags(UniqueId.Parse(uid), MessageFlags.None, customFlags, true);
我正在尋找有關如何僅使用 mailkit 將以下類別設置為電子郵件的信息。
客戶:Imap,郵箱:O365
IMAP 沒有類別或樣式的概念。
這取決於用戶的郵件客戶端通過在消息上設置自定義標志(假設 IMAP 服務器支持自定義標志)或僅以某種方式在用戶的桌面(或移動設備)本地存儲這些屬性來進行合成。
正如 Jazb 所說,IMAP 沒有“類別”的概念,客戶端可以找到存儲此狀態的替代方法。
我不確定 Office365 是否支持存儲自定義關鍵字(也稱為自定義標志),但您可以做的是創建一個測試文件夾,並在該文件夾中添加 6 條消息,每個類別 1 條,為它們提供易於提示您的主題您將它們分配到哪個類別中(例如“主題:藍色類別”)。
然后使用MailKit 來獲取MessageSummaryItems.Flags | MessageSummaryItems.Envelope
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.