{"id":3812,"date":"2013-03-22T15:20:25","date_gmt":"2013-03-22T13:20:25","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=3812"},"modified":"2013-06-25T23:24:42","modified_gmt":"2013-06-25T21:24:42","slug":"html-formatted-content-in-the-description-field-of-an-icalendar","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/html-formatted-content-in-the-description-field-of-an-icalendar","title":{"rendered":"HTML formatted content in the description field of an iCalendar"},"content":{"rendered":"<p>By default, the iCalendar specification allows only plain text to be used in the description of an Event object. <\/p>\n<h2>X-ALT-DESC header<\/h2>\n<p>However Outlook can recognize HTML formatted content. This is supported using an additional field in the Event object called &#8220;X-ALT-DESC&#8221;, rather than the existing field:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nDESCRIPTION:Reminder\r\nX-ALT-DESC;FMTTYPE=text\/html:&lt;!DOCTYPE HTML PUBLIC &quot;&quot;-\/\/W3C\/\/DTD HTML 3.2\/\/E\r\n N&quot;&quot;&gt;&lt;HTML&gt;&lt;BODY&gt;\\nhtml goes here\\n&lt;\/BODY&gt;&lt;\/HTML&gt;\r\n<\/pre>\n<p>Using Mail.dll you can set this field with no extra hassle:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nAppointment appointment = new Appointment();\r\nEvent e = appointment.AddEvent();\r\ne.XAltDescription = @&quot;&lt;!DOCTYPE HTML PUBLIC &quot;&quot;-\/\/W3C\/\/DTD HTML 3.2\/\/EN&quot;&quot;&gt;&lt;HTML&gt;&lt;BODY&gt;\r\nhtml goes here\r\n&lt;\/BODY&gt;&lt;\/HTML&gt;&quot;;\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim appointment As New Appointment()\r\nDim e As &#x5B;Event] = appointment.AddEvent()\r\ne.XAltDescription = &quot;&lt;!DOCTYPE HTML PUBLIC &quot;&quot;-\/\/W3C\/\/DTD HTML 3.2\/\/EN&quot;&quot;&gt;&lt;HTML&gt;&lt;BODY&gt;&quot; _ \r\n &amp; vbCr &amp; vbLf &amp; &quot;html goes here&quot;  _ \r\n &amp; vbCr &amp; vbLf &amp; &quot;&lt;\/BODY&gt;&lt;\/HTML&gt;&quot;\r\n<\/pre>\n<div class=\"well\">\nLearn how to <a href=\"\/blog\/send-icalendar-meeting-requests\">send iCalendar meeting requests in .NET<\/a>\n<\/div>\n<h2>Adding custom headers<\/h2>\n<p>This is also good sample to show <strong>how to add a custom header<\/strong> to any PDI object:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nAppointment appointment = new Appointment();\r\nEvent e = appointment.AddEvent();\r\n\r\nconst string html = @&quot;&lt;!DOCTYPE HTML PUBLIC &quot;&quot;-\/\/W3C\/\/DTD HTML 3.2\/\/EN&quot;&quot;&gt;&lt;HTML&gt;&lt;BODY&gt;\r\nhtml goes here\r\n&lt;\/BODY&gt;&lt;\/HTML&gt;&quot;;\r\n\r\nPdiHeader header = new PdiHeader(&quot;X-ALT-DESC&quot;, html);\r\nheader.KeyParameters.Add(new KeyValues(&quot;FMTTYPE&quot;, &quot;text\/html&quot;));\r\ne.AddCustomHeader(header);\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim appointment As New Appointment()\r\nDim e As &#x5B;Event] = appointment.AddEvent()\r\n\r\nConst  html As String = &quot;&lt;!DOCTYPE HTML PUBLIC &quot;&quot;-\/\/W3C\/\/DTD HTML 3.2\/\/EN&quot;&quot;&gt;&lt;HTML&gt;&lt;BODY&gt;&quot; _\r\n &amp; vbCr &amp; vbLf &amp; &quot;html goes here&quot; _\r\n &amp; vbCr &amp; vbLf &amp; &quot;&lt;\/BODY&gt;&lt;\/HTML&gt;&quot;\r\n\r\nDim header As New PdiHeader(&quot;X-ALT-DESC&quot;, html)\r\nheader.KeyParameters.Add(New KeyValues(&quot;FMTTYPE&quot;, &quot;text\/html&quot;))\r\ne.AddCustomHeader(header)\r\n<\/pre>\n<h2>ALTREP parameter<\/h2>\n<p>It is worth mentioning that RFC defines a way of specifying HTML content. The problem is that, it requires additional source (like email attachment or http address). Address of this resource, for example using &#8220;cid:&#8221; is set using ALTREP DESCRIPTION header:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nDESCRIPTION;ALTREP=&quot;CID:part3.msg.970415T083000@example.com&quot;:\r\n Project XYZ Review Meeting will include the following agenda\r\n   items: (a) Market Overview\\, (b) Finances\\, (c) Project Man\r\n agement\r\n<\/pre>\n<p>Mail.dll supports this feature also. <\/p>\n<p>First we&#8217;ll define MIME object containing html data. Note that we are setting ContentId property.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nMimeText html = new MimeFactory().CreateMimeText();\r\nhtml.ContentType = ContentType.TextHtml;\r\nhtml.Text = &quot;&lt;html&gt;&lt;body&gt;Html&lt;\/body&gt;&lt;\/html&gt;&quot;;\r\nhtml.ContentId = &quot;part3.msg.970415T083000@example.com&quot;;\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim html As MimeText = New MimeFactory().CreateMimeText()\r\nhtml.ContentType = ContentType.TextHtml\r\nhtml.Text = &quot;&lt;html&gt;&lt;body&gt;Html&lt;\/body&gt;&lt;\/html&gt;&quot;\r\nhtml.ContentId = &quot;part3.msg.970415T083000@example.com&quot;\r\n<\/pre>\n<p>Now we&#8217;ll create event:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nAppointment appointment = new Appointment();\r\nEvent e = appointment.AddEvent();\r\n\r\ne.Description = &quot;Project XYZ Review Meeting will include the following agenda items: (a) Market Overview, (b) Finances, (c) Project Management&quot;;\r\ne.DescriptionAltRep = &quot;CID:&quot; + html.ContentId;\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim appointment As New Appointment()\r\nDim e As &#x5B;Event] = appointment.AddEvent()\r\n\r\ne.Description = &quot;Project XYZ Review Meeting will include the following agenda items: (a) Market Overview, (b) Finances, (c) Project Management&quot;\r\ne.DescriptionAltRep = &quot;CID:&quot; + html.ContentId\r\n<\/pre>\n<p>Finally we need to create an email with the event and html data:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\n\/\/ C#\r\n\r\nMailBuilder builder = new MailBuilder();\r\nbuilder.AddAttachment(html);\r\nbuilder.AddAppointment(appointment);\r\nIMail email = builder.Create();\r\n<\/pre>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n' VB.NET\r\n\r\nDim builder As New MailBuilder()\r\nbuilder.AddAttachment(html)\r\nbuilder.AddAppointment(appointment)\r\nDim email As IMail = builder.Create()\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>By default, the iCalendar specification allows only plain text to be used in the description of an Event object. X-ALT-DESC header However Outlook can recognize HTML formatted content. This is supported using an additional field in the Event object called &#8220;X-ALT-DESC&#8221;, rather than the existing field: DESCRIPTION:Reminder X-ALT-DESC;FMTTYPE=text\/html:&lt;!DOCTYPE HTML PUBLIC &quot;&quot;-\/\/W3C\/\/DTD HTML 3.2\/\/E N&quot;&quot;&gt;&lt;HTML&gt;&lt;BODY&gt;\\nhtml goes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,26,57],"class_list":["post-3812","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-icalendar","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3812"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=3812"}],"version-history":[{"count":13,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3812\/revisions"}],"predecessor-version":[{"id":4114,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/3812\/revisions\/4114"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=3812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=3812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=3812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}