title: attachments with ics file in c#
body: <p>I am trying to send an ICS (calendar) file to someone that read it using Office365, using C#.
  Sending just the ICS works fine. But I have to attach a file. 
  At this point, the mail is received without calendar, or the calendar is attached to the email and cannot be used, or the attachment is missing.
  I tried 2 different ways:<br>
  1. send attachment inside VEVENT, using ATTACH;ENCODING=BASE64;VALUE=BINARY;X-FILENAME=file.txt:, but this does not show any attachment in Office365 (like here: <a href="https://stackoverflow.com/questions/29104715/attaching-a-file-to-an-icalendar">Attaching a file to an iCalendar</a>)<br>
  2. send attachment as a separate file, and attach it to VEVENT using ATTACH:CID:, but this time the calendar file is displayed as attachment<br>
  <br>
  The second way should work if I can format the mail message to look like this: </p>
  
  <pre>
  multipart/mixed
    multipart/alternative
      text/plain
      text/calendar;method=REQUEST
    text/calendar (with a content-disposition:attachment)
  </pre>
  
  <p>(as described in <a href="https://stackoverflow.com/questions/19523861/multipart-email-with-text-and-calendar-outlook-doesnt-recognize-ics">Multipart email with text and calendar: Outlook doesn&#39;t recognize ics</a>)<br>
  If I send a calendar invite using Outlook365, the message looks like that.(but instead of the calendar as attachment, the image or doc is attached)<br><br></p>
  
  <p>but using System.Net.Mail.MailMessage, I can generate a message like this</p>
  
  <pre>
  multipart/mixed
    multipart/alternative
      text/plain
      text/calendar;method=REQUEST
    multipart/mixed
      text/plain (with a content-disposition:attachment)
  </pre>
  
  <p>Desktop version of Outlook 2007 shows both calendar and attachment, so it seems that Outlook365 is very strict about the format.</p>
  
  <p>But how can I send, using .NET classes, an email that does not have the extra multipart/mixed section? MailMessage class generate for the Attachments collection a new section with content type multipart/mixed, insead of adding them to the top level.</p>