0

I am attempting to attach an ICS file so that the recipient will see it as event in Outlook as opposed to an attachment.

I am 2 characters shy of producing an email with an identical attachment and I suspect this is the cause of why Outlook is still treating the ICS file as an attachment.

This is what Google Calendar produces and this work as expected (Outlook presents it as an event that I can RSVP to ):

Content-Type: application/ics; name="invite.ics"
Content-Disposition: attachment; filename="invite.ics"
Content-Transfer-Encoding: base64

I've unsuccessfully attempted to reproduce this.

My first attempt was:

            byte[] byteArray = Encoding.UTF8.GetBytes(ics2);
            MemoryStream stream = new MemoryStream(byteArray);
            Attachment a = new Attachment(stream, "invite.ics", "application/ics");
            a.ContentDisposition.DispositionType = @"attachment; filename=""invite.ics""";

which produced the following attachment (almost identical but missing the 2 double-quotes around invite.ics)

Content-Type: application/ics; name=invite.ics
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="invite.ics"

My second attempt was to add double-quotes:

            byte[] byteArray = Encoding.UTF8.GetBytes(ics2);
            MemoryStream stream = new MemoryStream(byteArray);
            Attachment a = new Attachment(stream, @"""invite.ics""", "application/ics");
            a.ContentDisposition.DispositionType = @"attachment; filename=""invite.ics""";

but this produces the content type name with escaped double-quotes (which I don't need or want).

Content-Type: application/ics; name="\"invite.ics\""
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="invite.ics"

How do I set the attachment content type name with only double-quotes around the name value: "invite.ics"

Jay Cummins
  • 1,039
  • 2
  • 14
  • 31
  • don't directly assign the filename. use the `FileName` property of `ContentDisposition` – Daniel A. White Jul 24 '23 at 17:57
  • @DanielA.White I did attempt that but that produces a Content-Type value of `Content-Type: application/ics` and Outlook treats the ICS as an attachment. – Jay Cummins Jul 24 '23 at 18:20

1 Answers1

0

The filename is not important and works even without the " ", you have some different problems:

  • You are missing the method content-type, if you have the 'METHOD' set in your file, you also need to change this.

When used in a MIME message entity, the value of this property MUST be the same as the Content-Type "method" parameter value. If either the "METHOD" property or the Content-Type "method" parameter is specified, then the other MUST also be specified. source

  • The content-type should be 'text/calendar'
  • additionally the content-type of your mail also plays a role, 'Content-Type: multipart/mixed;' works for me. This is just a tipp, it may even work with what you are using now, just wanted to mention it.

As example:

Content-Type: text/calendar; charset="utf-8"; method="CANCEL"
Content-Disposition: attachment; filename="related_events/related_events_canceled.ics"
Content-Transfer-Encoding: base64

QkVHSU46VkNBTEVOREFSCk...

Here i have the method="CANCEL", because this is a Mail to cancel a Event, alternative you can use "REQUEST" or "PUBLISH" to create a event (here some more informations : here)

REQUEST: used to send 1 event, that shows up as meeting.

PUBLISH: more used to send multiple events, that can be imported by clicking on the attachment, (vary depending on the email client)

Bissy
  • 16
  • 3