含有ics内容的邮件无法被outlook识别

本文关键字:outlook 识别 ics 含有 | 更新日期: 2023-09-27 17:50:44

我正在尝试发送带有日历附件的多部分电子邮件。当没有附件文件时,outlook可以很好地识别邀请并显示日历事件块。但是当我额外添加ics文件作为附件outlook不显示日历块。我该怎么修理它?

MailMessage message = new MailMessage(new MailAddress(_replyAddress), new MailAddress(to)) { Subject = subject, Body = body };
message.IsBodyHtml = isBodyHtml;
message.BodyEncoding = Encoding.UTF8;
message.SubjectEncoding = Encoding.UTF8;
var attach = new System.Net.Mail.Attachment(stream, nameOfAttachFile, "application/ics");
ContentDisposition desposition = attach.ContentDisposition;
desposition.Inline = false;
desposition.FileName = nameOfAttachFile;
message.Attachments.Add(attach);
System.Net.Mime.ContentType mimeType = new System.Net.Mime.ContentType("text/calendar; method=REQUEST");
AlternateView icalView = AlternateView.CreateAlternateViewFromString(attachText, mimeType);
icalView.TransferEncoding = TransferEncoding.QuotedPrintable;
message.AlternateViews.Add(icalView);
client.Send(message);

日历字符串:

                "BEGIN:VCALENDAR",
                          "PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN",
                          "VERSION:2.0",
                          "CALSCALE:GREGORIAN",
                          "METHOD:REQUEST",
                          "BEGIN:VEVENT",
                          "DTSTART;TZID=Europe/London:" + message.date.Date.ToString("yyyyMMdd''T")+message.time.Substring(0,5).Replace(":","")+"00", 
                          "DTEND;TZID=Europe/London:"  + message.date.Date.ToString("yyyyMMdd''T")+message.time.Substring(6,5).Replace(":","")+"00", 
                          "DTSTAMP:" + DateTime.Now.ToUniversalTime().ToString("yyyyMMdd'T'HHmmss'Z'"),
                           "LAST-MODIFIED:"+ DateTime.Now.ToUniversalTime().ToString("yyyyMMdd'T'HHmmss'Z'"),
                          "ORGANIZER;CN=" + message.userBookerFullName + ":mailto:" + message.userBookerEmail,
                          "UID:" + input.JobRef + "@example.com",
                          "STATUS:CONFIRMED",
                          "TRANSP:OPAQUE",
                          "LOCATION:" + message.studioAddress, 
                          "DESCRIPTION:" + Description.Replace("'r'n","''n").Replace(";","'';").Replace(",","'',"),
                          "SUMMARY:" + Subject,
                          "SEQUENCE:" + ((input.template == MessageTemplate.BookingChangeConfirmationWithCharges || 
                                            input.template == MessageTemplate.BookingChangeConfirmationWithoutCharges ||
                                            input.template == MessageTemplate.PresentersChangeInvitation
                                          ) ? "1" : "0"),
                     "END:VEVENT",
                     "END:VCALENDAR" 

含有ics内容的邮件无法被outlook识别

您的问题可能有其他原因,但有些客户端无法识别上述MIME结构。参见带文本和日历的多部分电子邮件:Outlook不识别ics