Click here to Skip to main content
15,886,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,
When I was trying to delete everything other than a normal email.
I want to delete appointments, Meetings etc.

C#
Appointment appointment = new Appointment(service);

appointment.Subject = subject;

appointment.Body = body;

appointment.Delete(DeleteMode.MoveToDeletedItems);  

And i was also trying to select all read emails and delete them.

 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");
                        }
                    }
                    } 



Could you please help me to solve this

C#
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.InternalDelete(DeleteMode deleteMode, Nullable`1 sendCancellationsMode, Nullable`1 affectedTaskOccurrences, Boolean suppressReadReceipts)
   at Microsoft.Exchange.WebServices.Data.Item.Delete(DeleteMode deleteMode, Boolean suppressReadReceipts)
   at Microsoft.Exchange.WebServices.Data.Item.Delete(DeleteMode 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
Posted
Updated 18-Aug-14 23:57pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900