We have a C# console app which sends out registration confirmation emails for local events. I just added logic to attach an .ICS calendar appointment reminder to the email, specifying UTC times.
When a user gets the email and adds the appointment to his/her calendar it should adjust to the local PC’s environment’s time, but isn’t doing so. E.g., in my test, the event is from 11:30 AM - 1:00 PM in San Diego. When I (in the Central time zone) open the email attachment and add to calendar, it should come over as 1:30 PM - 3:00 PM, but is still doing 11:30 - 1:00 PM.
I’ve seen http://erics-notes.blogspot.com/2013/05/fixing-ics-time-zone.html advising to add a VTIMEZONE block and a timezone reference to DTSTART & DTEND (like “DTSTART;TZID=America/Los_Angeles:20130602T130000”) but in that example he’s not using UTC time.
The.ICS attachment file contains this; sorry for the extra line breaks, but when they're not there, it runs it all together. Note the DTSTART & DTEND “Z” universal times specified:
BEGIN:VCALENDAR
PRODID:-//Save to my Calendar
VERSION:2.0
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20170622T163000Z
DTEND:20170622T180000Z
DTSTAMP:20170718T134127Z
UID:6f59cf3b-99b5-4935-8f7c-3cb4c2e7a53f
CREATED:20170718T134127Z
LAST-MODIFIED:20170718T134127Z
X-ALT-DESC;FMTTYPE=text/html:<a href="http://mycompany.net/Events/12345">Party<a>
DESCRIPTION:mycompany.net/Events/12345
LOCATION:Restaurant name, 123 Elm, San Diego CA
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:My company’s event
END:VEVENT
END:VCALENDAR
I appreciate any advice... thanks!
My code... pretty unremarkable, but note that I'm converting the start & end times to UTC:
private static Attachment CreateEventCalendarReminder(DataRow dr)
{
var sb = new StringBuilder();
string nowUTCString = DateTime.Now.ToUniversalTime().ToString("yyyyMMddTHHmmssZ");
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("PRODID:-//Save to my Calendar");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("METHOD:PUBLISH");
//sb.AppendLine("TZ:+00");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("DTSTART:" + DateTime.Parse(dr["StartDate"].ToString()).ToUniversalTime().ToString("yyyyMMddTHHmmssZ"));
sb.AppendLine("DTEND:" + DateTime.Parse(dr["EndDate"].ToString()).ToUniversalTime().ToString("yyyyMMddTHHmmssZ"));
sb.AppendLine("DTSTAMP:" + nowUTCString);
sb.AppendLine("UID:" + Guid.NewGuid());
sb.AppendLine("CREATED:" + nowUTCString);
sb.AppendLine("LAST-MODIFIED:" + nowUTCString);
sb.AppendLine("X-ALT-DESC;FMTTYPE=text/html:"
+ "Thank you for registering for our event. Click "
+ (string)dr["EventDescHyperlink"]
+ " DetermineWhichEmailsToSend view the event details. We look forward to seeing you Attachment the EventArgs and appreciate your support.");
sb.AppendLine("DESCRIPTION:" + (string)dr["EventDescURL"]);
sb.AppendLine("LOCATION:" + (string)dr["VenueCombinedInfo"]);
sb.AppendLine("SEQUENCE:0");
sb.AppendLine("STATUS:CONFIRMED");
sb.AppendLine("SUMMARY:" + "My Company" + (string)dr["OfficeName"] + " Event");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");
var calendarBytes = Encoding.UTF8.GetBytes(sb.ToString());
MemoryStream ms = new MemoryStream(calendarBytes);
return new System.Net.Mail.Attachment(ms, "EventReminder.ics", "text/calendar");
}