HTML formatted content in the description field of an iCalendar

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 “X-ALT-DESC”, rather than the existing field:

DESCRIPTION:Reminder
X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//E
 N""><HTML><BODY>\nhtml goes here\n</BODY></HTML>

Using Mail.dll you can set this field with no extra hassle:

// C#

Appointment appointment = new Appointment();
Event e = appointment.AddEvent();
e.XAltDescription = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//EN""><HTML><BODY>
html goes here
</BODY></HTML>";
' VB.NET

Dim appointment As New Appointment()
Dim e As [Event] = appointment.AddEvent()
e.XAltDescription = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//EN""><HTML><BODY>" _ 
 & vbCr & vbLf & "html goes here"  _ 
 & vbCr & vbLf & "</BODY></HTML>"

Adding custom headers

This is also good sample to show how to add a custom header to any PDI object:

// C#

Appointment appointment = new Appointment();
Event e = appointment.AddEvent();

const string html = @"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//EN""><HTML><BODY>
html goes here
</BODY></HTML>";

PdiHeader header = new PdiHeader("X-ALT-DESC", html);
header.KeyParameters.Add(new KeyValues("FMTTYPE", "text/html"));
e.AddCustomHeader(header);
' VB.NET

Dim appointment As New Appointment()
Dim e As [Event] = appointment.AddEvent()

Const  html As String = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 3.2//EN""><HTML><BODY>" _
 & vbCr & vbLf & "html goes here" _
 & vbCr & vbLf & "</BODY></HTML>"

Dim header As New PdiHeader("X-ALT-DESC", html)
header.KeyParameters.Add(New KeyValues("FMTTYPE", "text/html"))
e.AddCustomHeader(header)

ALTREP parameter

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 “cid:” is set using ALTREP DESCRIPTION header:

DESCRIPTION;ALTREP="CID:part3.msg.970415T083000@example.com":
 Project XYZ Review Meeting will include the following agenda
   items: (a) Market Overview\, (b) Finances\, (c) Project Man
 agement

Mail.dll supports this feature also.

First we’ll define MIME object containing html data. Note that we are setting ContentId property.

// C#

MimeText html = new MimeFactory().CreateMimeText();
html.ContentType = ContentType.TextHtml;
html.Text = "<html><body>Html</body></html>";
html.ContentId = "part3.msg.970415T083000@example.com";
' VB.NET

Dim html As MimeText = New MimeFactory().CreateMimeText()
html.ContentType = ContentType.TextHtml
html.Text = "<html><body>Html</body></html>"
html.ContentId = "part3.msg.970415T083000@example.com"

Now we’ll create event:

// C#

Appointment appointment = new Appointment();
Event e = appointment.AddEvent();

e.Description = "Project XYZ Review Meeting will include the following agenda items: (a) Market Overview, (b) Finances, (c) Project Management";
e.DescriptionAltRep = "CID:" + html.ContentId;
' VB.NET

Dim appointment As New Appointment()
Dim e As [Event] = appointment.AddEvent()

e.Description = "Project XYZ Review Meeting will include the following agenda items: (a) Market Overview, (b) Finances, (c) Project Management"
e.DescriptionAltRep = "CID:" + html.ContentId

Finally we need to create an email with the event and html data:

// C#

MailBuilder builder = new MailBuilder();
builder.AddAttachment(html);
builder.AddAppointment(appointment);
IMail email = builder.Create();
' VB.NET

Dim builder As New MailBuilder()
builder.AddAttachment(html)
builder.AddAppointment(appointment)
Dim email As IMail = builder.Create()

Tags:   

Questions?

Consider using our Q&A forum for asking questions.