How to empty the Gmail Trash using C #
I tried to access my Gmail inbox using the InterImap library. My messages are displayed here, but I can't delete messages. I also found the "EmptyFolder ()" method, but it doesn't work.
All that worked for me was MoveMessageToFolder (), but that's not what I need.
Please help me to remove my trash bin with C # using the same or any other library. I need some sample code that does this.
Here is the code I was able to write.
var config = new InterIMAP.IMAPConfig("imap.gmail.com", "<my gmail username>", "<my gmail password", true, true, "");
var client = new InterIMAP.Synchronous.IMAPClient(config, new InterIMAP.IMAPLogger(config, new object[] { }), 1);
var trash = client.Folders["[Gmail]"].SubFolders["Trash"];
trash.EmptyFolder();
client.Logoff();
Thanks in Advance.
source to share
If you delete a message from your Inbox or one of your custom folders, it will still appear in [Gmail] / All Mail.
Here's why: In most cases, deleting a message simply removes the folder label from the message, including the label that identifies the message as being in the Inbox.
[Gmail] / All Mail shows all your messages, whether or not they have labels attached.
If you want to permanently delete a message from all folders:
- Move it to the [Gmail] / Trash folder.
- Remove it from the [Gmail] / Trash folder.
You can find more details here: http://www.limilabs.com/blog/delete-email-permanently-in-gmail
source to share
I don't like manually deleting the trash folder in Gmail. This is complete spam every day. So I copied the C # code to make this work for me. I downloaded and used mail.dll from Limilabs, evaluation version. Create a Gmail password for apps. Here is the code:
using System;
using Limilabs.Client.IMAP;
using System.Collections.Generic;
namespace delete_gmail_trash
{
class Program
{
static void Main(string[] args)
{
using (Imap imap = new Imap())
{
imap.ConnectSSL("imap.gmail.com");
imap.UseBestLogin("username@gmail.com", "password for Gmail apps");
// Recognize Trash folder
List<FolderInfo> folders = imap.GetFolders();
CommonFolders common = new CommonFolders(folders);
FolderInfo trash = common.Trash;
// Find all emails we want to delete
imap.Select(trash);
List<long> uidList = imap.Search(Flag.All);
foreach (long uid in uidList)
{
imap.DeleteMessageByUID(uid);
Console.WriteLine("{0} deleted", uid);
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
imap.Close();
}
}
}
}
source to share