[英]O365 using Mailkit to Delete mail?
I have been working on this small console app to read through a mailbox. 我一直在研究这个小型控制台应用程序,以通读邮箱。 It works fine but after it has finished reading through the mails, I want it to move them to the Deleted post folder. 它工作正常,但是在阅读完邮件之后,我希望它将其移到“ 已删除的邮件”文件夹中。 I found other questions related to this, but it didn't seem to fix it. 我发现了与此有关的其他问题,但似乎并没有解决。 I don't get any errors and the Seen
flag works flawless. 我没有任何错误, Seen
标志完美无瑕。 Feel free to comment in case of questions. 如有问题,请随时发表评论。
DateTimeOffset test = DateTime.Now;
using (var client = new ImapClient())
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("Imap.outlook.com", 993, true);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("Email@mail.com", "password");
var inbox = client.Inbox;
inbox.Open(FolderAccess.ReadWrite);
Console.WriteLine("Total messages: {0}", inbox.Count);
Console.WriteLine("Recent messages: {0}", inbox.Recent);
for (int i = 0; i < inbox.Count; i++)
{
var message = inbox.GetMessage(i);
Console.OutputEncoding = System.Text.Encoding.ASCII;
test = message.Date;
inbox.AddFlags(i , MessageFlags.Seen, true);
inbox.AddFlags(i, MessageFlags.Deleted, true); // Doesn't do anything.
Console.WriteLine("Emne: {0}", message.Subject);
Console.WriteLine("Fra: {0}", message.From);
Console.WriteLine("id: {0}", test);
Console.WriteLine(" ");
}
Console.ReadLine();
client.Disconnect(true);
}
Hello i have found the answer, after alot of searching and testing, 您好,经过大量搜索和测试,我找到了答案,
inbox.AddFlags(i, MessageFlags.Deleted, true);
marked it for being deleted, but didn't move it to either Delete post or anything, I found that if i run the 将其标记为已删除,但没有将其移动到“删除帖子”或其他任何内容,我发现如果我运行
inbox.Expunge();
it removes all the messages marked for being deleted. 它将删除所有标记为要删除的消息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.