Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailKit Delete single message from gmail

Tags:

c#

gmail

I am using MailKit (https://github.com/jstedfast/MailKit) to connect to google apps via imap, how can I delete a single message though ? (I am fine to have it moved to trash, just need it out of the inbox.

So far I have it connected, downloading, parsing links from message bodies. I just need this one last action to have what I need.

Thanks!

like image 517
BradMcA Avatar asked May 15 '14 11:05

BradMcA


People also ask

Can you delete a single message in Gmail?

Open the Gmail app . Open the message. (If you want to stay in your inbox, tap the letter or photo next to the message). Tap Delete .

Can you delete replies on Gmail?

From the reply, press the down arrow on your keyboard and then press Delete.

Can I delete Gmail message for everyone?

Once your inbox appears, click Select All option under the top banner if you want to remove all of your messages from Inbox. In case you need to delete only several messages, mark the empty checkbox on the left from the email groups of your choice. Once all the emails are selected, push the Trash button.


1 Answers

To delete a message from a folder on the IMAP server, this is all you need to do:

client.Inbox.AddFlags (new int[] { index }, MessageFlags.Deleted);

or

client.Inbox.AddFlags (new UniqueId[] { uid }, MessageFlags.Deleted);

Now the message is marked as \Deleted on the server.

You can then purge the folder of all deleted items by calling:

client.Inbox.Expunge ();

If you are using UIDs instead of indexes and the IMAP server supports the UIDPLUS extension (check the client.Capabilities), you can expunge just a selected set of messages like this:

if (client.Capabilities.HasFlag (ImapCapabilities.UidPlus))
    client.Inbox.Expunge (new UniqueId[] { uid });
like image 158
jstedfast Avatar answered Sep 18 '22 17:09

jstedfast