473,385 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Use C# code to Delete all read outlook emails, meetings and appointments in EWS

4
hi,
When I was trying to delete everything other than a normal email.
I want to delete appointments, Meetings etc.
Expand|Select|Wrap|Line Numbers
  1. Appointment appointment = new Appointment(service);
  2.  
  3. appointment.Subject = subject;
  4.  
  5. appointment.Body = body;
  6.  
  7. appointment.Delete(DeleteMode.MoveToDeletedItems);
  8.  
And i was also trying to select all read emails and delete them.
Expand|Select|Wrap|Line Numbers
  1.  int readEmailCount = 0;
  2.  
  3.                     SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, true));
  4.  
  5.                     ItemView view = new ItemView(999);
  6.  
  7.                     FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, view);
  8.                     readEmailCount = findResults.Items.Count;
  9.                     Console.WriteLine("Number of emails read : " + readEmailCount);
  10.  
  11.                     for (int i = 0; i < readEmailCount; ++i )
  12.                     {
  13.                         while(emailMessage.Subject != null)
  14.                         {
  15.                         if (i > 0)
  16.                         {
  17.                             Console.WriteLine("================================================");
  18.                             Console.WriteLine("\n");
  19.                             Console.WriteLine("{0}.Read mail from outlook inbox", ++i);
  20.                             Console.WriteLine(string.Format("Subject:-     {0}", emailMessage.Subject));
  21.                             // emailMessage.Delete(DeleteMode.MoveToDeletedItems);
  22.                             Console.WriteLine("================================================");
  23.                             Console.WriteLine("\n");
  24.                         }
  25.                     }
  26.                     }                
  27.  
Could you please help me to solve this

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
Aug 19 '14 #1
0 1623

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: none | last post by:
Hi, Any one know of some code to read cobol data files.... thanks timb
4
by: Ecohouse | last post by:
I need to be able to access an Outlook folder and read each email and pull data from the email into tables in Access and move the email to another folder. I now about automation but am not sure...
0
by: John E Katich | last post by:
When attempt to use the Event Wizard I get the following error message: "Add/Remove of the function impossible, because the parent class code is read only" The Project was convert from VC 6.0....
5
by: Mad Scientist Jr | last post by:
can someone post code to read an mp3, windows media file and PCM WAV file header and return the play time in minutes/seconds ? thanks
0
by: rsoni1011 | last post by:
Hi, How can I read outlook data files (*.pst) thru java code and put the specific mails in the seperate folder.
1
by: disha manikumar | last post by:
Simple java code to read an excel sheet and extract only few fields by treating the excel sheet as a flat file. Can anyone suggest a simple java code for this?
1
by: KEN | last post by:
I have created an app in C# that sends xml messages to a client via MSMQ. I have another app that savesthe xml data sent back but I have to post each xml in the messages. Could someone give me...
4
by: pooker75 | last post by:
I have a car.txt file and the first line is vin no., second line is model, third line is mfg, and 4th line is year. I may have an unlimited no. of vin numbers and I need the code to read the vin no....
11
by: alivip | last post by:
how to ingrate my code to read text in in parent folder contain sub folders and files for example folder name is cars and sub file is Toyota,Honda and BMW and Toyota contain file name Camry and...
0
by: veron | last post by:
hi. i want to send a sms to activate a device to open or close. can i use vb6 to write code to read sms from GSM modem? and how to use vb6 to write code to read sms from GSM modem?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.