How to Send an iCal File as an Exchange Appointment

Creating an iCal is rather straightforward, so is sending out an email with the iCal file attached therein.

What is required in our case is to automate sending out an appointment thru’ MS Exchange in a way that it behaves as though an appointment has been manually sent by someone thru’ Exchange.
This would mean that the appointment has to appear in the Exchange Calendar whether or not the recipient remembers to accept the appointment.
This is not possible with a typical iCal sent as an attachment in an email as the recipient would need to open the iCal file and save it before it appears in the Exchange Calendar (sort of an import function).

Apart from making use of Exchange API, a much simpler solution would be to (still) send the iCal as an attachment in an email but “trick” Exchange into recognising the mail as an Exchange appointment.

Credits to this website for first uncovering the solution.

First and foremost, understand the difference between an Appointment and a Meeting Request. The former doesn’t require inviting attendees while the latter infers inviting some attendees.

While the iCal file is a standard, the attaching email is special in that:
  1. the email subject becomes the name of the event/ appointment (and supersedes the summary of the iCal)
  2. it must not contain any attachment
  3. if the email contains a content body, the body will supersede the description in the iCal
  4. it can only have the view/ part containing the iCal

The email-sending code looks like the following:

  1: MailMessage mm = new MailMessage("<sender>", "<recipient>");
  2:  
  3: mm.Subject = "<The Name of the Appointment>";
  4: mm.Headers.Add("content-class", "urn:content-classes:calendarmessage");
  5:  
  6: AlternateView calPart = new AlternateView("<filepath and name of iCal>", \
  7: 	new ContentType("text/calendar; method=REQUEST; name=\"<iCal filename>\""));
  8:  
  9: calPart.TransferEncoding = TransferEncoding.SevenBit;
 10:  
 11: mm.AlternateViews.Add(calPart);
 12:  
 13: return mm;

In line 7



  • the name part of the ContentType is strictly not necessary for Exchange but is required for non-Exchange servers to determine the name of the attachment.

  • the method depends on whether this is an appointment (method=PUBLISH) or meeting request (method=REQUEST) or a meeting cancellation (method=CANCEL)


The attached iCal file looks like the following:

  1: BEGIN:VCALENDAR
  2: PRODID:-//Microsoft Corporation//Outlook MIMEDIR//EN
  3: VERSION:2.0
  4: METHOD:REQUEST
  5: BEGIN:VTIMEZONE
  6: TZID:Singapore Standard Time
  7: BEGIN:STANDARD
  8: DTSTART:16010101T000000
  9: TZOFFSETFROM:+0800
 10: TZOFFSETTO:+0800
 11: END:STANDARD
 12: END:VTIMEZONE
 13: BEGIN:VEVENT
 14: CATEGORIES:<Category>
 15: CLASS:PUBLIC
 16: CREATED:20120831T100824Z
 17: DESCRIPTION:<Content or Agenda of the appointment> \n\n
 18: DTEND;TZID="Singapore Standard Time":20120903T160000
 19: DTSTAMP:20120831T100824Z
 20: DTSTART;TZID="Singapore Standard Time":20120903T140000
 21: PRIORITY:5
 22: SEQUENCE:0
 23: SUMMARY;LANGUAGE=en-us:<Name of the iCal Event>
 24: TRANSP:OPAQUE
 25: UID:<Some unique GUID e.g. 000012345>
 26: BEGIN:VALARM
 27: TRIGGER:-PT15M
 28: ACTION:DISPLAY
 29: DESCRIPTION:Reminder
 30: END:VALARM
 31: END:VEVENT
 32: END:VCALENDAR

Again in line 4, the method depends on the nature of the message (appointment or meeting request).
That is all required for things to work.

Some salient references/ websites are:




  • Reference for iCal standard here
  • MSDN on Exchange Server Protocol (esp. X-)
  • iCal validation services here and here
  • .NET iCal implementation here

Comments

Popular posts from this blog

Understanding ITIL Service Management the UML way…

How to depict (Professional-Looking) Logical Network Diagrams in Astah