hi,
When I was trying to delete everything other than a normal email.
I want to delete appointments, Meetings etc.
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));
Console.WriteLine("================================================");
Console.WriteLine("\n");
}
}
}
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.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