Cancel outlook meeting requests via MailMessage in C#

巧了我就是萌 提交于 2019-12-18 03:26:18

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/2654743/cancel-outlook-meeting-requests-via-mailmessage-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!