通过C#中的MailMessage取消Outlook会议请求

时间:2010-04-16 16:51:34

标签: c# outlook mailmessage alternateview

我正在使用C#中的ASP.NET MVC 1框架创建一个应用程序,其中我有用户注册事件。注册后,我创建了一个Outlook会议请求

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();
    }

一旦构建,我使用MailMessage,并使用备用视图发送会议请求:

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);

当用户在Outlook中收到电子邮件时,它会显示为会议请求,而不是普通电子邮件。

这也适用于发送会议请求的更新。我遇到的唯一问题是我不知道发送取消的正确格式。我试图在文本编辑器中检查一些会议请求取消,但似乎无法确定取消/创建之间格式的差异。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:6)

根据RFC 2445,您只需设置STATUS:CANCELLED

即可