Two questions about ical.net

1.6k views Asked by At

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.

My first question is: is it possible to send the message as appointment and not as attachment, so the user can avoid open it and then save the date?

Second: 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);

And this is for sending the reminder; note that if I don't "attach" the ics, the alternate view seems to be ineffective.

var message = new MailMessage();
message.To.Add(new MailAddress(receiverRecipient));
message.From = new MailAddress(senderRecipient);
message.Subject = messageTitle;
message.Body = "The attachment contains the reminder";
message.IsBodyHtml = true;
var smtpClient = new SmtpClient(ConfigurationManager.AppSettings["SmtpSrv"], Convert.ToInt32(ConfigurationManager.AppSettings["SmtpPort"]));
var cred = new NetworkCredential(ConfigurationManager.AppSettings["SmtpUser"], ConfigurationManager.AppSettings["SmtpPwd"]);
smtpClient.Credentials = cred;

System.Net.Mime.ContentType contype = new System.Net.Mime.ContentType("text/calendar");
contype.Parameters.Add("method", "REQUEST");
contype.Parameters.Add("name", "Scadenza.ics");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(icalString, contype);

message.AlternateViews.Add(avCal);

message.Attachments.Add(new Attachment(GenerateStreamFromString(icalString), contype));

smtpClient.Send(message);
0

There are 0 answers