How to extract(retrieve) Appointments/Meetings from incoming email (eml file) in .NET using C#

Hello Friends,


We work with CRM web application in sharepoint 2010 environment. We are having one custom sharepoint document library list. We have configured e-mail option on that list so once any email comes to that particular id, it goes into that document library list. And after that we have made one email parser which extract that eml file using Microsoft CDO introp object and retrieve all necessary information using sharepoint’s SPItemEventReciever ItemAdded event.
Now we have requirement of parsing Calendar Appointments/Meetings on same list when any email arrives onto that id. I create one calendar meeting from my outlook and adding that email id as recipient. once i send invite from outlook that email comes into my sharepoint document library. And when i debug on SPItemEventReciever’s ItemAdded event, .eml file does not consist any relevant data for Appointment/Meetings. I have gone through some initial overview of Aspose.Emails and I think it might be helpful to us.
So Can Anyone please help me in how to extract calendar Appointment/Meetings/Events from incoming email (.eml file) in .NET using C#? Any step by step code and immediate help would be highly appreciated.


Thanks & Regards
Ashish Rajguru

Hi Ashish,

Thank you for writing to Aspose support team.

If you have access to the EML file, then you can use the following sample code to retrieve this and convert it to MapiCalender for retrieving further information. If this doesn’t help, please share a sample EML file for our investigation. We’ll look into this for assisting you further. You may also go through this article for reading Email Messages from Microsoft SharePoint Library for your info.

Sample Code:

MailMessage mailMsg = MailMessage.Load(“Sample.eml”);

MapiMessage mapiMsg = MapiMessage.FromMailMessage(mailMsg);

MapiCalendar meeting = (MapiCalendar)mapiMsg.ToMapiMessageItem();

Thank you Kashif.

It works for me. Now i am able to get Calendar Meeting information from eml file. I am still working on this part in deeply. if i’ll get stuck in any case, i’ll post my doubt here again.



Thanks & Regards
Ashish Rajguru

Hi Ashish,

Thank you for sharing your feedback. Please feel free to write to us in case you have any other query/inquiry in this regard.

Hello Kashif,


It works and extract data using mapi calendar for eml which is having outlook calendar Appointment/Meeting information but when any normal email comes which does not have outlook calendar or meeting information following line throws an exception.

MapiCalendar meeting = (MapiCalendar)mapiMsg.ToMapiMessageItem();

Exception: Unable to cast object of type ‘Aspose.Email.Outlook.MapiMessage’ to type ‘Aspose.Email.Outlook.MapiCalendar’.

How can i avoid above error? can you help me out in this?

Thanks & Regards
Ashish Rajguru

Hi Ashish,

You can take benefit from the MapiMessage’s MessageClass property for this purpose. The MapiMessage is a generic class that can load Outlook items such as Calendar, Tasks, etc. For Appointment/Meetings, the MessageClass is equal to “IPM.Appointment”, while for normal email, it is “IPM.Note”. So you can use this property to make your decision of avoiding the casting exception.Please let us know if we can be of any additional help to you in this regard.

Code Sample:

MapiMessage mapiMsg = MapiMessage.FromMailMessage(mailMsg);

if (mapiMsg.Message == “IPM.Appointment”)
//cast it to MapiCalendar, otherwise don’t cast

Hello,


Thanks for the earlier replies. I achieved the things which i wanted. Now we have new requirement regarding canceled meeting emails. if any event canceled then mail goes to server and all attendees. now i would like to check whether incoming calendar meeting is canceled meeting or normal meeting. how can i check or define that using code? There is also extra tag “Canceled:” added to subject after canceling to that event/meeting. how can i get actual subject of canceled event/meeting from incoming mail?


Thanks & Regards
Ashish Rajguru

Hi Ashish,


You may please extract the message and then convert it to MapiCalendar. This object contains “Subject” property which can be used to filter the cancelled meetings based on the presence of string Canceled. Please give it a try and let us know the feedback.