11

I'm creating an application using the ASP.NET MVC 1 framework in C#, where I have users that register for events. Upon registering, I create an outlook meeting request

public string BuildMeetingRequest(DateTime start, DateTime end, string attendees, string organizer, string subject, string description, string UID, string location)
    {
        System.Text.StringBuilder sw = new System.Text.StringBuilder();

        sw.AppendLine("BEGIN:VCALENDAR");
        sw.AppendLine("VERSION:2.0");
        sw.AppendLine("METHOD:REQUEST");
        sw.AppendLine("BEGIN:VEVENT");
        sw.AppendLine(attendees);
        sw.AppendLine("CLASS:PUBLIC");
        sw.AppendLine(string.Format("CREATED:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
        sw.AppendLine("DESCRIPTION:" + description);
        sw.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", end));
        sw.AppendLine(string.Format("DTSTAMP:{0:yyyyMMddTHHmmssZ}", DateTime.UtcNow));
        sw.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", start));
        sw.AppendLine("ORGANIZER;CN=\"NAME\":mailto:" + organizer);
        sw.AppendLine("SEQUENCE:0");
        sw.AppendLine("UID:" + UID);
        sw.AppendLine("LOCATION:" + location);
        sw.AppendLine("SUMMARY;LANGUAGE=en-us:" + subject);
        sw.AppendLine("BEGIN:VALARM");
        sw.AppendLine("TRIGGER:-PT720M");
        sw.AppendLine("ACTION:DISPLAY");
        sw.AppendLine("DESCRIPTION:Reminder");
        sw.AppendLine("END:VALARM");
        sw.AppendLine("END:VEVENT");
        sw.AppendLine("END:VCALENDAR");

        return sw.ToString();
    }

And once built, I use MailMessage, with an alternate view to send out the meeting request:

meetingInfo = BuildMeetingRequest(start, end, attendees, organizer, subject, description, UID, location);           

        System.Net.Mime.ContentType mimeType = new System.Net.Mime.ContentType("text/calendar; method=REQUEST");
        AlternateView ICSview = AlternateView.CreateAlternateViewFromString(meetingInfo,mimeType);
        MailMessage message = new MailMessage();

        message.To.Add(to);
        message.From = new MailAddress(from);
        message.AlternateViews.Add(ICSview);

        SmtpClient client = new SmtpClient();
        client.Send(message);

When users get the email in outlook, it shows up as a meeting request, as opposed to a normal email.

This works well for sending out updates to the meeting request as well. The only problem that I am having is that I do not know the proper format for sending out a cancellation. I've attempted to examine some meeting request cancellations in text editors and can't seem to pinpoint the difference in the format between cancelling/creating.

Any help on this is greatly appreciated.

skaffman
  • 398,947
  • 96
  • 818
  • 769
BTmuney
  • 125
  • 1
  • 1
  • 5

1 Answers1

8

According to RFC 2445 you just need to set STATUS:CANCELLED

Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • 5
    This helped, although when I used just that status keyword in the meeting request, outlook views it as a meeting edit. I managed to send a meeting cancellation by adding sw.AppendLine("METHOD:CANCEL"); sw.AppendLine("STATUS:CANCELLED"); Also, I needed to add another mime type for the cancellation System.Net.Mime.ContentType mimeType = new System.Net.Mime.ContentType("text/calendar; method=CANCEL"); Thanks. – BTmuney Apr 16 '10 at 20:32
  • 3
    @BTmuney After sending the meeting cancellation, did it also removes the meeting from the calendar? I tried this and its working and sending cancellation but it does not remove the existing meeting from calendar in outlook. – Fahad Hussain May 07 '14 at 11:13
  • Do we need to use the same UID for the cancellation email? – Lee Apr 27 '22 at 03:29
  • 1
    @Lee, see this thread: https://stackoverflow.com/a/10561761/231316 – Chris Haas Apr 27 '22 at 12:26