Outlook Email and ICS format -- Strange behavior

2.3k Views Asked by At

To begin, I will set the scenario. I am using the biweekly library to create a VEvent and an ICalendar. Everything is working fine (code below). I can successfully send a calendar invite to Google and the appropriate 'Accept, Decline, Add to Calendar' options are available.

When I send the same message to Outlook, I do not receive the correct invite. The message is formatted in such a way that it expects the recipient to send the invite - not be invited, nor add to his/her calendar.

The framework:

Java - JavaMailSender - Spring Boot - biweekly

The code is operational. The issue in is the difference in which Outlook handles the calendar invite.

Here is the Java code...

@Service
public class CalendarEvent {

private JavaMailSender javaMailSender;

@Autowired
public CalendarEvent(JavaMailSender javaMailSender) {
    this.javaMailSender = javaMailSender;
}

public void createCal() throws MessagingException, ParseException, IOException {

    ICalendar ical = new ICalendar();

    VEvent event = new VEvent();

    Attendee attendee = new Attendee("Juniper", "[email protected]");
    attendee.setRsvp(true);
    attendee.setRole(Role.ATTENDEE);
    attendee.setParticipationStatus(ParticipationStatus.NEEDS_ACTION);
    attendee.setParticipationLevel(ParticipationLevel.REQUIRED);

    event.addAttendee(attendee);

    event.setSummary("hello");

    DateTime dt = new DateTime(2016, 12, 28, 12, 0);
    DateTime et = new DateTime(2016, 12, 28, 13, 30);
    Date starts = (Date) dt.toDate();
    Date ends = (Date) et.toDate();

    DateStart thisStart = new DateStart(starts, true);
    DateEnd dateEnd = new DateEnd(ends, true);

    event.setDateStart(thisStart);
    event.setDateEnd(dateEnd);

    Duration reminder = new Duration.Builder().minutes(15).build();
    Trigger trigger = new Trigger(reminder, Related.START);
    Action action = new Action("DISPLAY");
    VAlarm valarm = new VAlarm(action, trigger);
    event.addAlarm(valarm);

    Duration duration = new Duration.Builder().hours(1).build();
    event.setDuration(duration);

    event.setUid("555xxx");
    event.setOrganizer("[email protected]");
    event.setLocation("Small");

    ical.addEvent(event);

    String str = Biweekly.write(ical).go();

    MimeMessage message = javaMailSender.createMimeMessage();
    message.addHeaderLine("charset=UTF-8");
    message.addHeaderLine("component=VEVENT");
    message.addHeaderLine("method=REQUEST");

    message.setFrom("[email protected]");
    message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
    message.setSubject("You're Invited to a Meeting");

    // Create the message part
    BodyPart messageBodyPart = new MimeBodyPart();

    // Fill the message
    messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
    messageBodyPart.setHeader("Content-ID", "calendar_message");
    messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(str, "text/calendar")));// very important


    Multipart multipart = new MimeMultipart();


    multipart.addBodyPart(messageBodyPart);


    message.setContent(multipart);

    javaMailSender.send(message);

}

}

Here is the ICS...

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Michael Angstadt//biweekly 0.6.0//EN BEGIN:VEVENT 
DTSTAMP:20161223T203840Z ATTENDEE;RSVP=TRUE;ROLE=REQ-  
PARTICIPANT;PARTSTAT=NEEDS-ACTION;CN=Juniper:mail
 to:[email protected]
SUMMARY:hello
DTSTART:20161228T170000Z
DTEND:20161228T183000Z
DURATION:PT1H
UID:555****
ORGANIZER:mailto:[email protected]
LOCATION:Small
BEGIN:VALARM
ACTION:DISPLAY
TRIGGER;RELATED=START:PT15M
END:VALARM
END:VEVENT
END:VCALENDAR

Here is the Opened Outlook Email (notice how it is a composed message)...

enter image description here

Here is the Opened Gmail Email...

enter image description here

I have found the documentation to be limited and was hoping somebody may have/is encountered/ecountering the same issue. Thanks for reading.

2

There are 2 best solutions below

1
On

I did away with the biweekly library...although I feel like the solution would be quite simple and I might revisit the issue. For the record, biweekly is a great library for helping in the creation of VEVENTS and VCALENDARS inside Java.

I resorted back to making the ics manually. This format is completely functional and works with both Gmail and Outlook.

    StringBuffer sb = new StringBuffer();

    StringBuffer buffer = sb.append(
            "BEGIN:VCALENDAR\n"
            + "PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n"
            + "VERSION:2.0\n"
            + "METHOD:REQUEST\n"
            + "BEGIN:VTIMEZONE\n"
            + "TZID:America/New_York\n"
            + "X-LIC-LOCATION:America/New_York\n"
            + "BEGIN:STANDARD\n"
            + "DTSTART:20071104T020000\n"
            + "TZOFFSETFROM:-0400\n"
            + "TZOFFSETTO:-0500\n"
            + "TZNAME:EST\n"
            + "END:STANDARD\n"
            + "BEGIN:DAYLIGHT\n"
            + "DTSTART:20070311T020000\n"
            + "TZOFFSETFROM:-0500\n"
            + "TZOFFSETTO:-0400\n"
            + "TZNAME:EDT\n"
            + "END:DAYLIGHT\n"
            + "END:VTIMEZONE\n"
            + "BEGIN:VEVENT\n"
            + "ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" + email + "\n"
            + "ORGANIZER:MAILTO:hockeyonicethricewastoldcold?.com\n"
            + "DTSTART;TZID=America/New_York:" + invite.getDateStart() + "\n"
            + "DTEND;TZID=America/New_York:" + invite.getDateEnd() + "\n"
            + "LOCATION:Conference room\n"
            + "TRANSP:OPAQUE\n"
            + "SEQUENCE:0\n"
            + "UID:" + invite.getUID() + "\n"
            + "DTSTAMP:20051206T120102Z\n"
            + "CATEGORIES:Meeting\n"
            + "DESCRIPTION:" + invite.getDescription() + "\n"
            + "SUMMARY:" + invite.getDescription() + "\n"
            + "PRIORITY:5\n"
            + "CLASS:PUBLIC\n"
            + "BEGIN:VALARM\n"
            + "TRIGGER:PT1440M\n"
            + "ACTION:DISPLAY\n"
            + "DESCRIPTION:Reminder\n"
            + "END:VALARM\n"
            + "END:VEVENT\n"
            + "END:VCALENDAR");

    MimeMessage message = javaMailSender.createMimeMessage();
    message.addHeaderLine("charset=UTF-8");
    message.addHeaderLine("component=VEVENT");
    message.addHeaderLine("method=REQUEST");

    message.setFrom(invite.getUserID());
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
    message.setSubject(invite.getSubject());

    BodyPart messageBodyPart = new MimeBodyPart();

    messageBodyPart.setHeader("Content-Class", "urn:content-classes:calendarmessage");
    messageBodyPart.setHeader("Content-ID", "calendar_message");
    messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(buffer.toString(), "text/calendar")));

    Multipart multipart = new MimeMultipart();

    multipart.addBodyPart(messageBodyPart);

    message.setContent(multipart);

    javaMailSender.send(message);

}
0
On

I had the same problem. Adding ical.setMethod("REQUEST"); solved it for me.