Skip to content

Instantly share code, notes, and snippets.

@naik899
Created September 14, 2019 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naik899/5c8ec71bc54051ee29a727ba269fdf30 to your computer and use it in GitHub Desktop.
Save naik899/5c8ec71bc54051ee29a727ba269fdf30 to your computer and use it in GitHub Desktop.
using Ical.Net;
using Ical.Net.DataTypes;
using Ical.Net.Serialization.iCalendar.Serializers;
using Ical.Net.Serialization;
...
...
...
MailMessage message = new MailMessage();
message.To.Add("naik899@gmail.com");
message.From = new MailAddress("info@company.com", "Company, Inc");
message.Subject = "subject";
message.Body = "emailbody";
message.IsBodyHtml = true;
...
...
...
var calendar = new Ical.Net.Calendar();
foreach (var res in reg.Reservations) {
calendar.Events.Add(new Event {
Class = "PUBLIC",
Summary = res.Summary,
Created = new CalDateTime(DateTime.Now),
Description = res.Details,
Start = new CalDateTime(Convert.ToDateTime(res.BeginDate)),
End = new CalDateTime(Convert.ToDateTime(res.EndDate)),
Sequence = 0,
Uid = Guid.NewGuid().ToString(),
Location = res.Location,
});
}
var serializer = new CalendarSerializer(new SerializationContext());
var serializedCalendar = serializer.SerializeToString(calendar);
var bytesCalendar = Encoding.UTF8.GetBytes(serializedCalendar);
MemoryStream ms = new MemoryStream(bytesCalendar);
System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ms, "event.ics", "text/calendar");
message.Attachments.Add(attachment);
...
...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment