I have a mail sniffer program running on an Inbox in Exchange Server 2010 that checks emails at certain intervals. I would like to know if it somehow is possible to programmatically check with EWS (Exchange Web Services) if an email (EmailMessage) is a meeting invite (calendar request) without loading the attachment.
I know I can check if an attachment is an Microsoft.Exchange.WebServices.Data.ItemAttachment
and then, after loading the email check if this is an Microsoft.Exchange.WebServices.Data.Appointment
. But this only checks if the attachment is an invite. Theoretically someone could forward an email with amongst other thing an email invite. Then the email is really not a meeting invite, just a forwarded email.
Can you know if an email is a meeting invite without loading the attachment? Should this not be possible with EWS, is there an authorative source for this?
Edit: Forwarded emails
This is outside the question, but I originally asked:
Alternatively (but not what I am hoping for), is there a way to know if an email was forwarded so that I can handle them differently?
This has been answered here. But I still would like to get an answer for my question as this answer only helps creating a workaround for some cases.
Thanks in advance!
You can leverage the EmailMessage
Message Class ItemSchema.ItemClass
property to determine what type an item is. Here is a snippet to help you out...
FindItemsResults<Item> mailItems = inbox.FindItems(new ItemView(1000) { PropertySet = new PropertySet(ItemSchema.Id, ItemSchema.HasAttachments, ItemSchema.Subject, ItemSchema.ItemClass) });
foreach (EmailMessage message in messageItems)
{
if (message.ItemClass == "IPM.Schedule.Meeting.Request")
// we have a meeting request
}