简体   繁体   English

O365使用Mailkit删除邮件?

[英]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.

相关问题 在控制台应用程序中使用图形 sdk 从 o365 获取用户邮件 - Get user mail from o365 using graph sdk in a console app 如何使用C#中的EWS托管API获取多个O365邮件ID的邮件详细信息 - How could I fetch multiple o365 mail details for mail ids using EWS managed API in c# O365使用REST API创建事件 - O365 Create Events using REST API C#O365 ews身份验证 - c# O365 ews authentication 升级到O365破坏了EWS自动发现 - Upgrade to O365 broke EWS Autodiscover 使用来自单个域管理员帐户的O365 REST API访问其他用户日历 - Accessing another user calendar using the O365 REST API from a single domain admin account 使用Azure AD身份验证获取承载访问令牌以访问o365资源 - Obtaining bearer access token to access o365 resource, using Azure AD auth 在Office SharePoint O365的子站点中使用C#CSOM创建列表 - Create list using C# CSOM in a subsite on Office SharePoint O365 使用O365统一API组文件上传方法时,文件大小是否有限制? - Is there a file size limit when using the O365 Unified API Group Files upload method? 使用OpenIdConnect(O365)进行外部登录的ASP.NET身份-无法获得声明? - ASP.NET Identity with External Login using OpenIdConnect (O365) - Cannot get claims?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM