Created
September 14, 2019 08:59
-
-
Save naik899/5c8ec71bc54051ee29a727ba269fdf30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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