If you want to permanently delete a message from a folder:
- Move it to the [Gmail]/Trash folder.
- Delete it from the [Gmail]/Trash folder.
Here's the sample that deletes emails from IMAP sent folder permanently:
using(Imap imap = new Imap())
{
imap.ConnectSSL("imap.gmail.com");
imap.UseBestLogin("pat@gmail.com", "password");
CommonFolders common = new CommonFolders(imap.GetFolders());
imap.Select(common.Sent);
// Find all emails we want to delete
List<long> uids = imap.Search(Expression.Subject("email to delete"));
// Move email to Trash
List<long> uidsInTrash = imap.MoveByUID(uids , common.Trash);
// Delete moved emails from Trash
imap.Select(common.Trash);
imap.DeleteMessageByUID(uidsInTrash);
imap.Close();
}
You can find more details here:
https://www.limilabs.com/blog/delete-email-permanently-in-gmail