Created
January 20, 2020 15:13
-
-
Save mdmsua/602d5f604dfe241331dd998ba42463c2 to your computer and use it in GitHub Desktop.
EWS Inbox Cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Microsoft.Exchange.WebServices.Data; | |
using static Microsoft.Exchange.WebServices.Data.SearchFilter; | |
namespace Inboxer | |
{ | |
class MainClass | |
{ | |
public static void Main() | |
{ | |
var service = new ExchangeService { Credentials = new WebCredentials("username", "password"), Url = new Uri("https://owa.check24.de/ews/exchange.asmx") }; | |
IList<ItemId> items = default; | |
do | |
{ | |
items = service.FindItems(WellKnownFolderName.Inbox, new ContainsSubstring(ItemSchema.Subject, "[PRTG Network Monitor]", ContainmentMode.Prefixed, ComparisonMode.Exact), new ItemView(byte.MaxValue) { PropertySet = PropertySet.FirstClassProperties })?.Select(item => item.Id).ToList(); | |
if (items?.Count > 0) | |
{ | |
Console.WriteLine($"Removing {items?.Count} items..."); | |
service.DeleteItems(items, DeleteMode.HardDelete, default, default); | |
Console.WriteLine("Done"); | |
} | |
} | |
while (items?.Count > 0); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment