Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MimeKit: How to delete an email by MessageId?

Tags:

c#

mimekit

I am using MailKit/MimeKit 1.2.7 (latest NuGet version).

Deleting an email with the ImapClient is pretty easy ...

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

... if you know the emails UniqueId or its Index.

In my case, I don't know either one nor the other. All I have is the message itself (MimeMessage) ad its MessageId.

I was hoping that MessageId == UniqueId, but obviously this is not the case.

Do I have any chance to delete an email by just having the corresponding MimeMessage/MessageId?

like image 651
Ingmar Avatar asked Jul 15 '15 09:07

Ingmar


1 Answers

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.

like image 50
jstedfast Avatar answered Nov 16 '22 10:11

jstedfast