public static void Run() { try { // ExStart:DeleteContactsFromExchangeServerUsingEWS // Create instance of EWSClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); string strContactToDelete = "John Teddy"; Contact[] contacts = client.GetContacts(client.MailboxInfo.ContactsUri); foreach (Contact contact in contacts) { if (contact.DisplayName.Equals(strContactToDelete)) { client.DeleteItem(contact.Id.EWSId, DeletionOptions.DeletePermanently); } } client.Dispose(); // ExEnd:DeleteContactsFromExchangeServerUsingEWS } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { // Connect to EWS const string mailboxUri = "https://outlook.office365.com/ews/exchange.asmx"; const string username = "******"; const string password = "******"; const string domain = "domain"; try { IEWSClient client = EWSClient.GetEWSClient(mailboxUri, username, password, domain); // ExStart:CaseSensitiveEmailsFiltering // Query building by means of ExchangeQueryBuilder class ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); builder.Subject.Contains("Newsletter", true); builder.InternalDate.On(DateTime.Now); MailQuery query = builder.GetQuery(); // ExEnd:CaseSensitiveEmailsFiltering // Get list of messages ExchangeMessageInfoCollection messages = client.ListMessages(client.MailboxInfo.InboxUri, query, false); Console.WriteLine("EWS: " + messages.Count + " message(s) found."); // Disconnect from EWS client.Dispose(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Run() { //ExStart: MoveItemsToInPlaceArchive const string mailboxUri = "<HOST>"; const string domain = @""; const string username = @"<USERNAME>"; const string password = @"<PASSWORD>"; NetworkCredential credentials = new NetworkCredential(username, password, domain); IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri); foreach (ExchangeMessageInfo msgInfo in msgCollection) { Console.WriteLine("Subject:" + msgInfo.Subject); client.ArchiveItem(client.MailboxInfo.InboxUri, msgInfo.UniqueUri); } client.Dispose(); //ExEnd: MoveItemsToInPlaceArchive }