我尝试使用 InterImap 访问我的 Gmail 邮箱图书馆。它在那里显示我的消息,但无法删除消息。我还找到了一种方法“EmptyFolder()”,但它不起作用。
所有对我有用的是 MoveMessageToFolder() 但这不是我需要的。
请帮助我使用相同或任何其他库使用 C# 清空我的回收站。我需要执行此操作的代码示例。
这是我设法编写的代码。
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();
提前致谢。
最佳答案
我不喜欢手动删除 Gmail 中的垃圾文件夹。每天都充斥着垃圾邮件。 所以我复制了 c# 代码来为我完成这项工作。我从评估版 Limilabs 下载并使用了 mail.dll。为应用创建 Gmail 密码。 这是代码:
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();
}
}
}
}
关于c# - 如何使用 C# 清空 Gmail 垃圾箱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9853838/