When I was trying to delete everything other than a normal email.
I want to delete appointments, Meetings etc.
Expand|Select|Wrap|Line Numbers
- Appointment appointment = new Appointment(service);
- appointment.Subject = subject;
- appointment.Body = body;
- appointment.Delete(DeleteMode.MoveToDeletedItems);
Expand|Select|Wrap|Line Numbers
- int readEmailCount = 0;
- SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, true));
- ItemView view = new ItemView(999);
- FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
- readEmailCount = findResults.Items.Count;
- Console.WriteLine("Number of emails read : " + readEmailCount);
- for (int i = 0; i < readEmailCount; ++i )
- {
- while(emailMessage.Subject != null)
- {
- if (i > 0)
- {
- Console.WriteLine("================================================");
- Console.WriteLine("\n");
- Console.WriteLine("{0}.Read mail from outlook inbox", ++i);
- Console.WriteLine(string.Format("Subject:- {0}", emailMessage.Subject));
- // emailMessage.Delete(DeleteMode.MoveToDeletedItems);
- Console.WriteLine("================================================");
- Console.WriteLine("\n");
- }
- }
- }
System.InvalidOperationException: This operation can't be performed because this service object doesn't have an Id.
at Microsoft.Exchange.WebServices.Data.ServiceObject. ThrowIfThisIsNew()
at Microsoft.Exchange.WebServices.Data.Item.InternalD elete(DeleteMode deleteMode, Nullable`1 sendCancellationsMode, Nullable`1 affectedTaskOccurrences, Boolean suppressReadReceipts)
at Microsoft.Exchange.WebServices.Data.Item.Delete(De leteMode deleteMode, Boolean suppressReadReceipts)
at Microsoft.Exchange.WebServices.Data.Item.Delete(De leteMode deleteMode)
at AP.Utils.MailUtil.SendMail_HTML(String from_address, String to_address, String cc_address, String subject, String body, String smtp_server, MailFileAttachment fileAttachment)
Thanks in advance