Cancel outlook meeting requests via MailMessage in C#
Asked Answered
E

1

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.

Eugene answered 16/4, 2010 at 16:51 Comment(0)
A
8

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

Abmho answered 16/4, 2010 at 17:42 Comment(4)
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.Eugene
@Eugene 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.Comfy
Do we need to use the same UID for the cancellation email?Dregs
@Lee, see this thread: https://mcmap.net/q/461421/-how-to-cancel-an-calendar-event-using-ics-filesAbmho

© 2022 - 2024 — McMap. All rights reserved.