1

I'm trying to send a multipart email with a calendar attachment. When there is no attachment file ics, invitation is recognized well by outlook and shows calendar event block. But when I additionally added ics file as attachment outlook doesn't show calendar block. How can I fix it?

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

Calendar strings:

                "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" 
datrax
  • 51
  • 5

1 Answers1

0

There might be other reasons for your issue but some clients do not recognize the above MIME structure. See Multipart email with text and calendar: Outlook doesn't recognize ics

Community
  • 1
  • 1
Arnaud Quillaud
  • 4,420
  • 1
  • 12
  • 8