I need send reminders to users of a web application.
To do this I use iCal.Net from nuget packages. Following instructions about the usage I'm able to send an email with an attachment containing the ics file.
Is it possible to format the event description as html and make it working on both Outlook office client and Chrome calendar?
On these clients I see plain text representation with all the html tags. I tested also on Windows 10 calendar where the event description is correctly displayed as html. Do I have to set something more?
This is my calendar string generation
var now = DateTime.Now;
var later = scadenza.Value;
var e = new Event
{
DtStart = new CalDateTime(later),
DtEnd = new CalDateTime(later),
Description = mailText,
IsAllDay = true,
Created = new CalDateTime(DateTime.Now),
Summary = $"Reminder for XYZ",
};
var attendee = new Attendee
{
CommonName = "…..",
Rsvp = true,
Value = new Uri("mailto:" + ConfigurationManager.AppSettings["ReminderReceiver"])
};
e. Attendees = new List<IAttendee> { attendee };
var calendar = new Calendar();
calendar.Events.Add(e);
var serializer = new CalendarSerializer(new SerializationContext());
var icalString = serializer.SerializeToString(calendar);
HTML formatting isn't part of the icalendar spec, so it's up to applications to add support for this via the non-standard property fields, which are designated with an
X-
prefix. (Further reading on non-standard properties if you're interested.)Google calendar
It doesn't look like Google calendar has any support for HTML-formatted events, so I think you're out of luck there.
Outlook
Outlook uses a number of these
X-
fields for various things; for HTML-formatted descriptions, it usesX-ALT-DESC
and specifiesFMTTYPE=text/html
like this:You may be able to get away with much simpler HTML, you'll have to test to see what Outlook supports/allows. The HTML block above was generated using Outlook 2013. I have successfully used that block and run it through a serialization round-trip with ical.net, and Outlook opens it without any fuss.
ical.net
Unfortunately you can't quite do this in ical.net due a bug with
CalendarProperty
serialization, but the workaround is just one line.This will produce HTML-formatted Outlook calendar events.
(When I fix the bug, I'll update this answer to remove the
string.Replace
call.)