I am trying to send a meeting invite with C# and am able to get what I want with a manually formatted static string - and here is the screenshot of what I was able to get with the static string
public static void SendEmailString()
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("song@company.com", "Song");
msg.To.Add(new MailAddress("John@company.com", "John"));
msg.Subject = "CS Inquiry";
msg.Body = "TESTING";
string test = @"BEGIN:VCALENDAR
PRODID: -//Company & Com//Credit Inquiry//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
ATTENDEE;CN=""John, Song"";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:song@company.com
ATTENDEE;CN=""Lay, Sean"";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:lins@company.com
ORGANIZER: John, Song
DTSTART:20171205T040000Z
DTEND:20171206T040000Z
LOCATION:New York
TRANSP:TRANSPARENT
SEQUENCE:0
UID:a16fbc2b-72fd-487f-adee-370dc349a2273asfdasd
DTSTAMP:20171027T215051Z
DESCRIPTION:Request for information regarding Test
SUMMARY:Summary
PRIORITY: 5
CLASS: PUBLIC
BEGIN:VALARM
TRIGGER:-PT1440M
ACTION: DISPLAY
DESCRIPTION:REMINDER
END:VALARM
END:VEVENT
END:VCALENDAR
";
SmtpClient sc = new SmtpClient("smtp.company.com");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(test, ct);
msg.AlternateViews.Add(avCal);
sc.Send(msg);
}
I am now trying to replicate that with iCal.Net (because the date and attendees are dynamic) and couldn't get what I want. Please see this screenshot of what I get with the code below:
public static void SendICal()
{
DateTime dtStart = new DateTime(2017, 12, 4);
DateTime dtEnd = dtStart.AddDays(1);
CalendarEvent e = new CalendarEvent()
{
DtStart = new CalDateTime(dtStart),
DtEnd = new CalDateTime(dtEnd),
DtStamp = new CalDateTime(DateTime.Now),
IsAllDay = true,
Sequence = 0,
Transparency = TransparencyType.Transparent,
Description = "Test with iCal.Net",
Priority = 5,
Class = "PUBLIC",
Location = "New York",
Summary = "Tested with iCal.Net Summary",
Uid = Guid.NewGuid().ToString(),
Organizer = new Organizer() {
CommonName = "John, Song",
Value = new Uri("mailto:song@company.com")
}
};
e.Attendees.Add(new Attendee()
{
CommonName = "John, Song",
ParticipationStatus = "REQ-PARTICIPANT",
Rsvp = true,
Value = new Uri("mailto:song.John@company.com")
});
e.Attendees.Add(new Attendee()
{
CommonName = "John, Sean",
ParticipationStatus = "REQ-PARTICIPANT",
Rsvp = true,
Value = new Uri("mailto:Johns@company.com")
});
Alarm alarm = new Alarm()
{
Action = AlarmAction.Display,
Trigger = new Trigger(TimeSpan.FromDays(-1)),
Summary = "Inquiry due in 1 day"
};
e.Alarms.Add(alarm);
Calendar c = new Calendar();
c.Events.Add(e);
CalendarSerializer serializer = new CalendarSerializer(new SerializationContext());
Console.WriteJohne(serializer.SerializeToString(c));
MailMessage msg = new MailMessage();
msg.From = new MailAddress("song.John@company.com", "Credit Inquiry");
msg.To.Add(new MailAddress("song.John@company.com", "Song John"));
msg.Subject = "CS Inquiry";
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(serializer.SerializeToString(c), ct);
msg.AlternateViews.Add(avCal);
//Response.Write(str);
// sc.ServicePoint.MaxIdleTime = 2;
SmtpClient sc = new SmtpClient("smtp.company.com");
sc.Send(msg);
}
I am not exactly sure what I am missing here. The iCalendar information generated from iCal.net is almost identical to the static string I used.
Thanks!