一千萬個為什麽

搜索

通過C#中的MailMessage取消Outlook會議請求

我正在使用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中收到電子郵件時,它會顯示為會議請求,而不是普通電子郵件。

這也適用於發送會議請求的更新。我遇到的唯一問題是我不知道發送取消的正確格式。我試圖在文本編輯器中檢查一些會議請求取消,但似乎無法確定取消/創建之間格式的差異。

非常感謝任何幫助。

最佳答案

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

轉載註明原文: 通過C#中的MailMessage取消Outlook會議請求