MailKit
MailKit copied to clipboard
Can't Delete message from GMail
Hello. I trashed a message and tried to Expunge it. But message still is in trash folder. Code:
var result = mailFolder.MoveTo(uniqueIds, trashFolder);
mailFolder.CloseAsync(true);
if (trashFolder.IsOpen) trashFolder.Close(false);
trashFolder.Open(MailKit.FolderAccess.ReadWrite);
trashFolder.SetFlags(result.Source, MailKit.MessageFlags.Deleted, true);
trashFolder.Expunge(result.Source);
trashFolder.Close(true);
How can i expunge the trash folder?
result.Source refers to the UIDs in the mailFolder and not the trashFolder. You want to use result.Destination when settings flags/expunging the trashFolder.
Hope that helps.
Also what looks kind of wrong...
mailFolder.CloseAsync(true); You need await mailFolder.CloseAsync(true); or ugly mailFolder.CloseAsync(true).Wait();
Thank you for answer. It is really helped me.