Send appointment email for Google Calendar appointment

1

I have a C # ASP.NET MVC application, in which the user can schedule an appointment. In this application he chooses a text for the appointment, a Date to happen and also chooses, as soon as he wants to be warned of the appointment, that generates a datetime for that date of the reminder.

The next step, I would create a "tool" that would be queried every 5 minutes if there are reminders to be sent to the user's email. From what I read, I would have to create a bat on the server to do that job.

The other option, in creating the appointment, is to send an email to the user, so that this email generated an automatic calendar for the user in the Google agenda, as it happens today with the airlines like TAM and BLUE . (All users have Google email.)

Does anyone know how these emails that generate appointments work in Google Calendar? What do you suggest?

    
asked by anonymous 16.10.2017 / 15:47

1 answer

1

To create an event that can be recreated across calendars such as Google and Apple Calendar, you can use iCalendar (* .ics) files.

There is iCal.NET, an open source .NET library for creating and manipulating files in this standard. It is available as NuGet package , just run

Install-Package Ical.Net

in the Visual Studio Package Manager.

MailMessage message = new MailMessage();
message.Subject = "Seu compromisso";
message.Body = "Adicione ao seu calendário!";
message.To.Add("[email protected]");
message.From = new MailAddress("[email protected]", "Fulano de Tal");

// criação do evento
calendar.Events.Add(new Event {
    Class = "PUBLIC",
    Summary = "Seu evento",
    Created = new CalDateTime(DateTime.Now),
    Description = res.Details,
    Start = new CalDateTime(Convert.ToDateTime(DateTime.Now)),
    End = new CalDateTime(Convert.ToDateTime(DateTime.Now.AddDays(5))),
    Sequence = 0,
    Uid = Guid.NewGuid().ToString(),
  });

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, "evento.ics", "text/calendar");
message.Attachments.Add(attachment);

In the example above, you can see how to use this library to generate the iCalendar file, create an email, and attach it.

The generated * .ics file follows this pattern (removed from from here ):

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
BEGIN:VEVENT
UID:[email protected]
DTSTAMP:19970714T170000Z
ORGANIZER;CN=John Doe:MAILTO:[email protected]
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR

I reiterate that the big gain in using this type of file is that it is accepted by many providers. Yahoo, Apple, Google and Microsoft accept this standard.

See how Outlook Web handles when there is a * .ics attached:

16.10.2017 / 23:55