Search code examples
asp.net-mvc-5icalendaroutlook.com

Emails with event invite generated by MVC application not synced with calendar in outlook.com


I am creating ASP.NET MVC5 application. One functionality is to send emails with event invitations. In Gmail client such generated email works fine. But in outlook.com even if the email has correct buttons - accept/tentative/decline - clicking on them won't sync that into the calendar itself.

I took some inspiration here:

StackOverflow Q1
StackOverflow Q2
StackOverflow Q3

Here is my current implementation:

I am using DDay.ical library for creating the event:

IICalendar iCal = new iCalendar();
iCal.Version = "2.0";
iCal.Method = "REQUEST";
iCal.ProductID = "[email protected]";

Event evt = iCal.Create<Event>();
evt.UID = Guid.NewGuid().ToString();
evt.Class = "PUBLIC";
evt.Created = new iCalDateTime(DateTime.Now);
evt.DTStamp = new iCalDateTime(DateTime.Now);
evt.Start = new iCalDateTime(DateTime.Now.AddHours(2));
evt.End = new iCalDateTime(DateTime.Now.AddHours(4));
evt.Location = "Party room";
evt.Description = "Awesome party";
evt.Summary = "Lets get wasted";
evt.Priority = 5;
evt.Transparency = TransparencyType.Transparent;

string res = new iCalendarSerializer().SerializeToString(iCal);
return res;

I am packing this event into email as an alternative view:

MailMessage email = new MailMessage();

email.To.Add(addressesToJoined);
email.Subject = Party;
email.Body = "";

if (!String.IsNullOrEmpty(calendarEvent))
{
    System.Net.Mime.ContentType calendarType = new System.Net.Mime.ContentType("text/calendar");
    calendarType.Parameters.Add("method", "REQUEST");

    AlternateView ICSview = AlternateView.CreateAlternateViewFromString(calendarEvent, calendarType);

    email.AlternateViews.Add(ICSview);

}

And here is the .ics itself:

BEGIN:VCALENDAR
VERSION:2.0
METHOD:REQUEST
PRODID:[email protected]
BEGIN:VEVENT
CLASS:PUBLIC
CREATED:20151115T152442
DESCRIPTION:Awesome party
DTEND:20151115T192442
DTSTAMP:20151115T142442Z
DTSTART:20151115T172442
LOCATION:Party room
PRIORITY:5
SEQUENCE:0
SUMMARY:Lets get wasted
TRANSP:Transparent
UID:1735cdca-cb36-4e6b-a1ec-4fb4149f798a
END:VEVENT
END:VCALENDAR

When this email comes to Gmail client, I can correctly see the invitation with option to add event into calendar, which works fine.

But in outlook.com even when the email itself is correctly recognized as invitation and I can see accept/tentative/decline buttons it does not work as expected. When I click for example accept option, new response email is created and when I send it out, I would expect, the event will be set in my calendar, however there is no event synced.

Can someone please see why events are not synced in calendar in outlook.com? Also, is there possibility in outlook.com to just set event in calendar, without sending response email? - invitations are auto-generated from system no need for response.

Thanks


Solution

  • Finally I've found a solution - there was missing ORGANIZER parameter of the VEVENT part in .ics. Gmail is able to handle that, Outlook.com not. So the trick was to add following line when setting DDay.iCal.Event object:

    evt.Organizer = new Organizer("[email protected]");
    

    Everything else remained untouched so the final look of the .ics which works in both - Gmail and Outlook.com is this:

    BEGIN:VCALENDAR
    VERSION:2.0
    METHOD:REQUEST
    PRODID:[email protected]
    BEGIN:VEVENT
    CLASS:PUBLIC
    CREATED:20151115T152442
    DESCRIPTION:Awesome party
    DTEND:20151115T192442
    DTSTAMP:20151115T142442Z
    DTSTART:20151115T172442
    LOCATION:Party room
    ORGANIZER:mailto:[email protected]
    PRIORITY:5
    SEQUENCE:0
    SUMMARY:Lets get wasted
    TRANSP:Transparent
    UID:1735cdca-cb36-4e6b-a1ec-4fb4149f798a
    END:VEVENT
    END:VCALENDAR
    

    Now it works fine.