Outlook未识别带有ics内容的邮件

时间:2015-05-25 15:32:09

标签: c# email outlook icalendar

我正在尝试发送带有日历附件的多部分电子邮件。当没有附件文件时,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" 

1 个答案:

答案 0 :(得分:0)

您的问题可能还有其他原因,但有些客户端无法识别上述MIME结构。见Multipart email with text and calendar: Outlook doesn't recognize ics