MailKit Delete single message from gmail

后端 未结 1 2083
一整个雨季
一整个雨季 2021-02-19 19:02

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, ju

相关标签:
1条回答
  • 2021-02-19 19:33

    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 });
    
    0 讨论(0)
提交回复
热议问题