简体   繁体   English

MimeKit:如何通过MessageId删除电子邮件?

[英]MimeKit: How to delete an email by MessageId?

I am using MailKit/MimeKit 1.2.7 (latest NuGet version). 我正在使用MailKit / MimeKit 1.2.7(最新的NuGet版本)。

Deleting an email with the ImapClient is pretty easy ... 使用ImapClient删除电子邮件非常简单......

client.Inbox.AddFlags(uniqueId, MessageFlags.Deleted, silent: true);

... if you know the emails UniqueId or its Index. ...如果您知道电子邮件UniqueId或其索引。

In my case, I don't know either one nor the other. 就我而言,我不知道其中任何一方。 All I have is the message itself (MimeMessage) ad its MessageId. 我所拥有的只是消息本身(MimeMessage)和它的MessageId。

I was hoping that MessageId == UniqueId, but obviously this is not the case. 我希望MessageId == UniqueId,但显然事实并非如此。

Do I have any chance to delete an email by just having the corresponding MimeMessage/MessageId? 我是否有机会通过拥有相应的MimeMessage / MessageId来删除电子邮件?

You could try doing something like this: 你可以尝试做这样的事情:

var uids = folder.Search (SearchQuery.HeaderContains ("Message-Id", message.MessageId));
folder.AddFlags (uids, MessageFlags.Deleted, silent: true);

Ideally, though, you'd keep track of the UniqueId that you used to fetch the message so that you can just use that value. 但是,理想情况下,您将跟踪用于获取消息的UniqueId ,以便您可以使用该值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM